File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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 Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Reseting an applet" Watch "Reseting an applet" New topic

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

Joined: Jul 08, 2003
Posts: 24195

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

Joined: Mar 22, 2005
Posts: 42959
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

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
I agree. Here's the link:
subject: Reseting an applet
jQuery in Action, 3rd edition