如何通过代码关闭java Applet
我正在开发一个java小程序。我希望它被代码关闭。我已经使用了 System.Exit(0)
但它不起作用。还有其他方法可以实现这一目标吗?
谢谢
I am developing a java applet. I want it to be closed by the code. I have used System.Exit(0)
but it is not working. Is there any other method to achieve this?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
至于评论说签名的小程序可以调用
System.exit(n)
。它可以在某些浏览器/JRE 组合中使用,但在其他浏览器/JRE 组合中则不能。在可以的情况下,它不应该,因为小程序可能与其他小程序共享虚拟机(现在不太常见),即使不这样做,用户也有责任通过以下方式关闭小程序:关闭页面。
小程序是网页中的访客。调用
System.exit(n)
就像烧毁宾馆一样。As to the comment that a signed applet can call
System.exit(n)
.It can in some browser/JRE combos., it can't in others. In the ones that it can, it shouldn't since an applet may share a VM with other applets (less common these days), and even if not, it is the user's responsibility to close an applet by closing the page.
An applet is a guest in a web page. Calling
System.exit(n)
is like burning down the guest house.小程序无法调用
System.exit(int);
。安全权限不允许小程序执行此操作。如果您尝试关闭浏览器窗口,即使您签署了代码并且浏览器/用户信任您,浏览器也不会让您关闭/关闭浏览器窗口。
如果您只想关闭从小程序创建的窗口/框架,这与关闭小程序外部的窗口没有什么不同。
An applet cannot call
System.exit(int);
. Security permissions don't let an applet do this.And if you are trying to close the browser window, even if you signed the code and the browser/user trusted you, the browser wouldn't let you shutdown/close the browser window.
If all you want to do is close a Window/Frame created from the applet, this is no different than closing a window outside of an applet.
尝试通过 javascript 删除 java applet 代码。
您的 html 示例:
您的 javascript 代码:
Try to remove java applet code by javascript.
Example your html:
your javascript code:
如上所述,退出小程序很简单,只需在要关闭小程序的 if(condition) 中添加 System.exit(0) 即可。虽然我描述的是
小程序查看器。但是,它确实工作得很好。
As said above,exiting applet is simple by adding System.exit(0) in if(condition) for which you want to close the applet.Though I am describing of
applet viewer.But,it certainly works fine.