How to gracefully end a java applet when user closes the page?

I'm executing some simple java games in html pages.
User goes to an index, clicks a button, opens a new page which runs the applet such as:
<applet code=gamename.class width=292 height=322>
< /applet

everything works fine except: with more complicated games when the user closes the window
then opens it again the user gets a load error from the game. and can't run it again until after closing the main page of the site.

I found
 an instance of java.exe is left running on the user's machine.
If I end it with task manager then the game can be launched again even though it had failed to load and would not have run again unless I closed the main page.
The problem seems to be timing in which the program is not having enough time to clean up when the page is closed.  Note sometimes the offending program doesn't fail to load again after the page is closed but it usually does.

Is there some way to force an orderly cleanup in ON Leave( or something like that?  
Or perhaps another explaination?

Who is Participating?
not really, its the responsibility of the applet to clean up after itself.
sounds like the applet is not doing that
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.