Results 1 to 2 of 2
Thread: Static variable
- 12-01-2008, 02:57 PM #1
Member
- Join Date
- Dec 2008
- Posts
- 1
- Rep Power
- 0
Static variable
I have 2 problems, first one is code from my class "Square":
When i try to run the project i get:Java Code:... private static Square mChosenSquare; ... public boolean isMarked() { boolean returnValue = false; if(mChosenSquare != null) { if((mChosenSquare.getCol() == this.getCol()) && (mChosenSquare.getRow() == this.getRow())) { returnValue = true; } } return returnValue; }
Exception in thread "main" java.lang.NullPointerException
at ravspelet.Square.isMarked(Square.java:57)
-----------------------------------------------------------------------
My second question is on this code:
I havent tested it yet because i still need to complete other parts of the program but i have a strong feeling the last part wont work (the paintComponent method)Java Code:private class PlayingField extends JPanel { private Graphics g; public PlayingField(MouseListener listener) { addMouseListener(listener); } public void paintSquare(int x,int y, Color color) { g.setColor(color); // -1 för att få en markering mellan rutorna g.drawRect(x*SQUARE_SIZE, y*SQUARE_SIZE, SQUARE_SIZE-1, SQUARE_SIZE-1); } public void paintPiece(int x,int y, Image image) { g.drawImage(image, x*SQUARE_SIZE, y*SQUARE_SIZE, SQUARE_SIZE-1, SQUARE_SIZE-1, null); } public void paintComponent(Graphics g) { super.paintComponent(g); } }
Any help is very much appreciated...
-
Similar Threads
-
Static variable context Errors ?
By Shyam Singh in forum New To JavaReplies: 16Last Post: 08-08-2008, 09:11 PM -
static variable
By udhayageetha in forum AWT / SwingReplies: 17Last Post: 07-07-2008, 11:22 AM -
About static variable
By MarkWilson in forum New To JavaReplies: 5Last Post: 06-27-2008, 01:43 PM -
Error: non-static variable height cannot be referenced from a static context at line
By fernando in forum AWT / SwingReplies: 1Last Post: 08-01-2007, 09:25 PM -
Help with static variable counter
By silvia in forum New To JavaReplies: 1Last Post: 07-19-2007, 07:53 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks