It's not a secret anymore!*
The moose likes Swing / AWT / SWT and the fly likes Why is this Image being painted? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Why is this Image being painted?" Watch "Why is this Image being painted?" New topic
Author

Why is this Image being painted?

Andrew Gary
Greenhorn

Joined: Aug 31, 2011
Posts: 8

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


Thanks in advance.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Aug 31, 2011
Posts: 8

Wow I feel stupid, I have figured it out.

Thank you for the help!
-Andrew
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why is this Image being painted?