如何显示从applet一个JFrame?(how to display a JFrame from

2019-10-21 05:13发布

我有这个类叫做PollFrame,在一个名为PollFrame.java文件扩展JFrame的。 PollFrame包含窗体。 我有一个小程序,其中有一个按钮。 当点击该按钮时,我想要显示的PollFrame。 我设置的actionPerformed为:

Pollframe poll = new PollFrame(); // This initializes the form
poll.setVisible(true);

然而,当我按一下按钮,我得到以下错误:

Exception in thread "AWT-EventQueue-2" java.security.AccessControlException: access denied (java.lang.RuntimePermission exitVM.0)
    at java.security.AccessControlContext.checkPermission(Unknown Source)
    at java.security.AccessController.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkPermission(Unknown Source)
    at java.lang.SecurityManager.checkExit(Unknown Source)
    at javax.swing.JFrame.setDefaultCloseOperation(Unknown Source)
    at com.org.pollFrame.initComponents(pollFrame.java:54)
    at com.org.pollFrame.<init>(pollFrame.java:11)
    at com.org.EmployeeApplet.requestRoomActionPerformed(EmployeeApplet.java:216)
    at com.org.EmployeeApplet.access$300(EmployeeApplet.java:7)
    at com.org.EmployeeApplet$4.actionPerformed(EmployeeApplet.java:71)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

在调用从applet另一个类文件禁止我猜他fromt上述错误。 有没有什么办法可以显示来自applet的PollFrame?

Answer 1:

好像你调用setDefaultCloseOperation()在你的JFrame,这提高了安全异常

你可以明确地调用另一个类从applet,但一些操作受到限制,例如。 无法打开本地文件,打开连接到其它机器...



Answer 2:

我有这个类叫做PollFrame,在一个名为PollFrame.java文件扩展JFrame的。 PollFrame包含窗体。 我有一个小程序,其中有一个按钮。 当点击该按钮时,我想要显示的PollFrame。

这是一个班轮:

applet.showDocument("PollFrame.jnlp", "_blank");

通过推出该框架PollFrame.jnlp将能够调用它喜欢的同时仍然沙箱任何默认关闭操作,因为它有一个单独的虚拟机。 是“总在最前面”它需要被信任(然后与所有其他应用程序。旨在始终在最前面打出来)。



文章来源: how to display a JFrame from an applet?