-
Can't figure out Static Error?
I can't figure out this static error, says non - static variable x,y,c, cannot be reference from a static context? Can anyone help out, something wrong with my code?
import java.awt.*;
import java.applet.*;
import java.awt.Color;
public class elephant extends animal {
private int x;
private int y;
private Color c = Color.blue;
public static void main(String [] args) {
int coordinate;
int coordinate2;
int position;
elephant elephant = new elephant(x, y, c);
for (int k = 0; k < args.length; k++) {
for (int i = 1; i < args.length; i ++) {
if (args.length > 0) {
coordinate = Integer.parseInt(args[k]);
coordinate2 = Integer.parseInt(args[i]);
x = coordinate;
y = coordinate2;
}
}
}
}
public elephant (int xx,int yy, Color cc){
x = xx;
y = yy;
c = cc;
}
public void paint(Graphics g) {
drawhead(g,200 + x,150 + y,80,80);
drawneck(g,280 + x,165 + y,10,50);
drawbody(g,290 + x,165 + y,150,150,10,10);
drawoutleg(g,290 + x,315 + y,20,70);
drawoutleg(g,310 + x,315 + y,10,50);
drawoutleg(g,420 + x,315 + y,20,70);
drawoutleg(g,410 + x,315 + y,10,50);
drawtail(g,440+ x,165+ y,50,10,45,10);
drawsmile(g,170+ x,200+ y,150,140,100,20);
draweyes(g,210+ x,160+ y,20,20);
drawSpots(g,Color.BLUE);
}
public void drawSpots(Graphics g, Color c) {
int[] x = getxspot();
int[] y = getyspot();
int [] size = getsize();
g.setColor(c);
for (int k = 0; k < 5; k ++) {
g.fillOval(x[k],y[k],size[k],size[k]);
}
}
public int [] getxspot() {
int [] array = new int [4];
array [0] = 300;
array [1] = 325;
array [2] = 350;
array [3] = 365;
return array;
}
public int [] getyspot() {
int [] array2 = new int [4];
array2 [0] = 160;
array2 [1] = 160;
array2 [2] = 160;
array2 [3] = 220;
return array2;
}
public int [] getsize() {
int [] array3 = new int [4];
array3 [0] = 25;
array3 [1] = 15;
array3 [2] = 25;
array3 [3] = 15;
return array3;
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks