Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to correctly stop a Java applet after window closing

Tags:

java

So, I made an applet game and put it on a webpage. I noticed that the sound kept playing after I closed the page that the applet was in. I did some research and found out that the applet keeps running, even after the page closes. I read that you are supposed to use the void destroy() and void stop() methods to dump all resources. Is there a proper way to completely stop the app? Currently I just have it create a nullpointerexception to crash the app upon closing.

like image 457
Ian Baer Avatar asked Jun 21 '26 07:06

Ian Baer


1 Answers

The destroy methode is there for this use, i would just use it, you can make sure it gets called when the applet is finished, you can also call it in the finalize section like:

public void finalize () {
    destroy();
}
like image 52
CloudyMarble Avatar answered Jun 22 '26 20:06

CloudyMarble



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!