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?

ARPYPREFAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mick BarryJava DeveloperCommented:
not really, its the responsibility of the applet to clean up after itself.
sounds like the applet is not doing that
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.