[英]How to correctly stop a Java applet after window closing
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.
我注意到在我关闭applet所在的页面后声音一直在播放。我做了一些研究,发现applet一直在运行,即使页面关闭之后也是如此。 I read that you are supposed to use the
void destroy()
and void stop()
methods to dump all resources. 我读到你应该使用
void destroy()
和void stop()
方法来转储所有资源。 Is there a proper way to completely stop the app? 有没有正确的方法来完全停止应用程序? Currently I just have it create a nullpointerexception to crash the app upon closing.
目前我只是创建了一个nullpointerexception来关闭应用程序崩溃。
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: 破坏方法是有用的,我会使用它,你可以确保它在applet完成时被调用,你也可以在finalize部分调用它,如:
public void finalize () {
destroy();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.