DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2004
    Posts
    103

    Question 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;
    }
    }

  2. #2
    Join Date
    Sep 2004
    Posts
    103

    Figured it out

    I figured it out I just didn't have Private Static Int In front of my X Y and Color values

  3. #3
    Join Date
    Feb 2004
    Posts
    808
    making everything static is poor programming practice.

    incidentally, it's "private static int" not "Private Static Int".. and your variables shouls start with lowercase x and y, not X and Y

    there is a big difference, and from what ive seen in your other post, you need to pay more heed to this (uppercase/lowercase thing)
    The 6th edict:
    "A thing of reference thing can hold either a null thing or a thing to any thing whose thing is assignment compatible with the thing of the thing" - ArchAngel, www.dictionary.com et al.
    JAR tutorial GridBag tutorial Inherited Shapes Inheritance? String.split(); FTP?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


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


Sponsored Links