This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling the repaint() method

 
chander shivdasani
Ranch Hand
Posts: 206
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> 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
Posts: 206
Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
did you add a listener to the button?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic