如何从小程序显示 JFrame?
我有一个名为 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您正在 JFrame 上调用
setDefaultCloseOperation()
,这会引发安全异常您可以明确地从小程序调用另一个类,但某些操作受到限制,例如。您无法打开本地文件,打开与其他计算机的连接......
It seems like you're calling
setDefaultCloseOperation()
on your JFrame, which raises the security exceptionYou 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...
这是一个单行代码:
由
PollFrame.jnlp
启动的框架将能够在仍处于沙盒状态时调用它喜欢的任何默认关闭操作,因为它将有一个单独的虚拟机。为了“始终处于领先地位”,它需要受到信任(然后与所有其他旨在始终处于领先地位的应用程序展开竞争)。This is a one liner:
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).