• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

cannot find symbol

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Ranch Hand
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 624
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Attractive, successful people love this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic