如何从小程序显示 JFrame?

发布于 2024-08-29 09:34:02 字数 2728 浏览 4 评论 0原文

我有一个名为 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)

我从上面的错误猜测禁止从小程序调用另一个类文件。有什么方法可以从小程序中显示 PollFrame 吗?

I have this class called PollFrame that extends JFrame in a file called PollFrame.java . PollFrame contains a form. I have an applet, which has a button in it. When the button is clicked, I want the PollFrame to be displayed. I set the ActionPerformed as:

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

However, when I click the button, I get the following error :

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)

I am guessing fromt he above error that calling another class file from an applet is prohibited. Is there any way I can display the PollFrame from the applet?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

神爱温柔 2024-09-05 09:34:03

看起来您正在 JFrame 上调用 setDefaultCloseOperation() ,这会引发安全异常

您可以明确地从小程序调用另一个类,但某些操作受到限制,例如。您无法打开本地文件,打开与其他计算机的连接......

It seems like you're calling setDefaultCloseOperation() on your JFrame, which raises the security exception

You can definitively call another class from an applet but some operations are restricted, eg. you can't open local files, open connections to other machines...

生死何惧 2024-09-05 09:34:03

我有一个名为 PollFrame 的类,它在名为 PollFrame.java 的文件中扩展了 JFrame 。 PollFrame 包含一个表单。我有一个小程序,里面有一个按钮。单击按钮时,我希望显示 PollFrame。

这是一个单行代码:

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

PollFrame.jnlp 启动的框架将能够在仍处于沙盒状态时调用它喜欢的任何默认关闭操作,因为它将有一个单独的虚拟机。为了“始终处于领先地位”,它需要受到信任(然后与所有其他旨在始终处于领先地位的应用程序展开竞争)。

I have this class called PollFrame that extends JFrame in a file called PollFrame.java . PollFrame contains a form. I have an applet, which has a button in it. When the button is clicked, I want the PollFrame to be displayed.

This is a one liner:

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

The frame launched by PollFrame.jnlp will be able to call any default close operation it likes while still sand-boxed, since it will have a separate VM. To be 'always on top' it will need to be trusted (and then fight it out with all the other apps. that aim to be always on top).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文