File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes cannot find symbol Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "cannot find symbol" Watch "cannot find symbol" New topic
Author

cannot find symbol

Jing Liang
Ranch Hand

Joined: Oct 23, 2006
Posts: 40
Hi guys, could someone please help with this error cannot find symbol

In my mouseReleased() method I called the method picked(int x, int y) and I get a error cannot find symbol boxes, but I thought that boxes is a Box class object, and I have declared it. Thanks

Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

In your picked(int x, int y) method of your "Box" class, you are referencing "boxes", but do not have a variable "boxes" defined anywhere. Your "GuessGame" class does have an instance variable "boxes", but that is not in anyway in scope for the outer class "Boxes".

Did you mean for "Box" to be an inner class?
Jing Liang
Ranch Hand

Joined: Oct 23, 2006
Posts: 40
I don't want Box to be inner class, so how can call on boxes[i][j] and set its showColor variables from the picked() method? thanks
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

You should not have to reference your boxes variable from the box class. A key to good Object Oriented Design is that objects are responsible for themselves. In your game, a Box does not need to know about the game board it is being used in. That is a concern for the GuessGame to worry about. By not coupling the Box class to the game board (i.e. the two dimensional array), you are free to use the the Box class not just a square like the current Game, but in other ways, such as in a line , or a cube (can you say Rubic's Cube Game ). What this means is your Box class does not need to know (i.e. store in variables) its X and Y position in the game board. Doing so would prevent you from using the Box in a cube (where there is an X, Y & Z position), or whatever board layout we might want. So I would pull those instance variables out of the Box class. Again, let the GuessGame class keep track of the game board.

Now with that in mind, we want the GuessGame Class to finds the particular box clicked on, get it from the array, and then call a method on that particular box reference to tell that particular box "you've been picked".
So in the mouseReleased(MouseEvent) method of the GuessGame, you have code to determine the X and Y position of the box that was clicked on. So use that to reference the box that was clicked on from your array. In the mouseReleased(MouseEvent) method, after you determine the row and column subscripts, do the following:



Then change your picked method to simply change the state of that box:



I did not look in detail at the algorithm you are using to determine the row and col subscript. Just remember that arrays are zero based. Does your algorithm take that into consideration?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: cannot find symbol