Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why is this Image being painted?

 
Andrew Gary
Greenhorn
Posts: 8
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on making a Tic-Tac-Toe game, and I can not figure out why an 'X' is painted in the top left spot every time the program is run.
It would probably help if you compiled and ran the program.

I believe the problem lies somewhere in the for loop on lines 53 - 72, but I have looked at it for hours, and can not figure it out.

Here is my code for the TicTacToe.java class.



And here is my code for the Spot.java class


Thanks for any help!
-Andrew
 
Paul Clapham
Sheriff
Pie
Posts: 20776
30
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrew Gary wrote:It would probably help if you compiled and ran the program.


Provided that I set up a user named "Andrew" on my hopefully-Windows computer and created some suitable directories for that user and put some suitable images in that directory...

Moving right along then, I looked at your code. I guessed you might be talking about the image which you assigned to a variable named "x" near the beginning. I thought I would search your code to see where that variable was being used, but I got tired of slogging through unrelated instances of the character "x" in the code. I know that "x" seems like a good variable name for an image which is an "X", but trust me, it isn't a good variable name.

So I was reduced to taking your suggestion of looking at the loop where you suspected the problem was located. (You probably suspect rightly.) You're complaining about an X image showing up where you didn't expect one? Then set a breakpoint at line 64 and see what the state of your variables is when your debugger stops there.

Edit: looking farther down from that loop, I see you have some code which does something based on where the user last clicked the mouse. What does it do if the user hasn't ever clicked the mouse?
 
Andrew Gary
Greenhorn
Posts: 8
Chrome Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow I feel stupid, I have figured it out.

Thank you for the help!
-Andrew
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic