本文介绍了如何从小程序显示 JFrame?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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)

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

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?

推荐答案

您似乎在 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...

这篇关于如何从小程序显示 JFrame?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-19 01:56
查看更多