java 如何通过代码关闭java Applet

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4507108/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 06:39:56  来源:igfitidea点击:

How to close java Applet through code

javaapplet

提问by Rashmi

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?

我正在开发一个java小程序。我希望它被代码关闭。我用过System.Exit(0)但它不起作用。有没有其他方法可以实现这一目标?

Thanks

谢谢

回答by Andrew Thompson

applet.getAppletContext().showDocument("ThanksForUsingOurApplet.html");

As to the comment that a signed applet can call System.exit(n).

至于签名小程序可以调用的注释System.exit(n)

It can in some browser/JRE combos., it can't in others. In the ones that it can, it shouldn'tsince 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.

它可以在某些浏览器/JRE 组合中使用,而在其他浏览器中则不能。在它可以的情况下,它不应该,因为小程序可能与其他小程序共享一个 VM(现在不太常见),即使不是,用户也有责任通过关闭页面来关闭小程序。

An applet is a guest in a web page. Calling System.exit(n)is like burning down the guest house.

小程序是网页中的访客。打电话System.exit(n)就像烧了宾馆。

回答by Mudassir

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.

小程序不能调用System.exit(int);. 安全权限不允许小程序这样做。如果您尝试关闭浏览器窗口,即使您签署了代码并且浏览器/用户信任您,浏览器也不会让您关闭/关闭浏览器窗口。

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.

如果您只想关闭从小程序创建的窗口/框架,这与关闭小程序外部的窗口没有什么不同。

回答by Heo ??t Hades

Try to remove java applet code by javascript. Example your html:

尝试通过 javascript 删除 java applet 代码。以你的 html 为例:

<button onclick="clickButton()">Click me</button>
<div id="appletCode">
     <applet width="200" height="200" archive="ImageIconApplet.jar"
        code="com.whitefang34.ImageIconApplet" name="test"/> 
</div>

your javascript code:

你的 javascript 代码:

function clickButton(){
     var SS = document.getElementById("appletCode");
    SS.innerHTML = "";
}

回答by Bhavik Mehta

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.

如上所述,通过在要关闭小程序的 if(condition) 中添加 System.exit(0) 来退出小程序很简单。虽然我描述的是小程序查看器。但是,它确实可以正常工作。