It's not a secret anymore!*
The moose likes Beginning Java and the fly likes Reseting an applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Reseting an applet" Watch "Reseting an applet" New topic
Author

Reseting an applet

Martin vanPutten
Ranch Hand

Joined: Mar 26, 2006
Posts: 124
How can I reset the applet by having a keypress such as "R" for reset? I made a game and when its over, I'd like the player to push "r" to simply reset it if they wish.


Live And Let Learn.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

Well, using a KeyListener. Implement a KeyListener, add it to the Applet, and in the implementation, do your resetting or whatever.


[Jess in Action][AskingGoodQuestions]
Martin vanPutten
Ranch Hand

Joined: Mar 26, 2006
Posts: 124
whats the command for reset?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41599
    
  55
There is no API call to put the applet back to its pristine state. You'll have to implement that.


Ping & DNS - my free Android networking tools app
Martin vanPutten
Ranch Hand

Joined: Mar 26, 2006
Posts: 124
I don't understand how to implement it. Can somebody give me a short example?
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Basically, write a method that reassigns all the variables back to what they were when the Applet was first initialized.

(I say "basically" because if the variables reference objects that change state, then those objects might need to be "reset" as well. And so on.)
[ May 18, 2006: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Reseting an applet