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

Calling the repaint() method

chander shivdasani
Ranch Hand

Joined: Oct 09, 2007
Posts: 206

I am developing a game called Tic Tac Toe. I first made a standalone application and then converted it into a JApplet.
In my game i have a button called as "New Game". Whenever a user presses this button the game is started all over again. The problem is, i have written some logic for it, but it is not working.

The problem is, i dont know wat to put in the paint method. In my case all the logic is implemented in init() and actionPerformed() method. So my paint method is empty. And when i call repaint(), it is having no effect.

Which logic should come in the paint method?

Below is the code which i have written till now.



Enjoy, Chander
SCJP 5, Oracle Certified PL/SQL Developer
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
> i dont know wat to put in the paint method.

you don't need to put anything there.

the game changes/paints itself via
pressedButton.setText(letter);

so, for new game, iterate the buttons clearing the x/o's via setText("")
and you would need to reset player turn and any other variable you use in the game
chander shivdasani
Ranch Hand

Joined: Oct 09, 2007
Posts: 206

To the above code, i added the following code in the actionPerformed method



Even after doing this,the "new game" button does not produce any effect
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
did you add a listener to the button?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling the repaint() method