Java 如何在单击按钮时关闭小程序

Java 如何在单击按钮时关闭小程序,java,applet,Java,Applet,如何从代码关闭小程序 我使用过System.exit(0),但它只抛出一堆异常,并没有关闭它。 我理解用户有责任关闭小程序,但仍然有办法吗?不要调用系统。在小程序中退出(0)。这可能导致浏览器关闭 更好的方法是在JFrame中运行应用程序,并使用启动应用程序。在actionPerformed(ActionEvent)方法中,调用 // end the applet by navigating to the 'applet ended' URL applet.getAppletContext().

如何从代码关闭小程序 我使用过System.exit(0),但它只抛出一堆异常,并没有关闭它。
我理解用户有责任关闭小程序,但仍然有办法吗?

不要调用
系统。在小程序中退出(0)
。这可能导致浏览器关闭


更好的方法是在
JFrame
中运行应用程序,并使用启动应用程序。

actionPerformed(ActionEvent)
方法中,调用

// end the applet by navigating to the 'applet ended' URL
applet.getAppletContext().showDocument(appletCloseURL);

我使用的是appletviewer,而不是任何用于显示applet的浏览器。那么为什么不将applet转换为应用程序呢?然后可以调用
系统。退出(0)