File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 24187
    
  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: 42919
    
  68
There is no API call to put the applet back to its pristine state. You'll have to implement that.
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reseting an applet