0

在启动通过浏览器创建 JWindow 的小程序时,java 控制台会抛出以下 AccessControlException:

访问被拒绝 java.awt.AWTPermission "setWindowAlwaysOnTop"

我希望 JFrame 始终位于顶部,在策略文件中授予权限以及使用特权代码,但它不能解决问题。我应该怎么做?

import java.applet.Applet;
import java.awt.Color;
import java.awt.Font;
import java.security.AccessController;
import java.security.PrivilegedAction;

import javax.swing.JButton;
import javax.swing.JFrame;


public class appletJFrame extends Applet
{

public void start()
{
    //create a frame
    final JFrame frame = new JFrame("FrameDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true); 

    //add a button
    JButton doneButton = new JButton("demo");
    doneButton.setFont(new Font("Calibri", doneButton.getFont().getStyle(), doneButton.getFont().getSize()));
    doneButton.setBackground(new Color(53,168,51));

    frame.getContentPane().add(doneButton);

    AccessController.doPrivileged(
            new PrivilegedAction<Object>() 
            {
                   public Object run()
                   {
                       frame.setAlwaysOnTop(true);//gives an error for this
                       return null;
                   }
            }

          );

}

}

这是我用来启动应用程序的 JNLP 文件:

<?xml version="1.0" encoding="UTF-8"?>
<jnlp spec="1.0+" href="Launcher.jnlp">

<information>
    <title>xyz</title>
    <vendor>xyz</vendor>
</information>

<resources>
    <!-- Application Resources -->
    <j2se version="1.6+"
          href="http://java.sun.com/products/autodl/j2se"/>
    <jar href="MyJar.jar"
        main="true" />      //can be resolved
    <jar href="jna.jar" />     //cannot be resolved(used as imports in main class)
    <jar href="platform.jar" />    //cannot be resolved(used as imports in main class)
    <jar href="xuggle-xuggler.jar" />    //cannot be resolved(used as imports in main class)
    <jar href="xuggle-xuggler-test.jar" />    //cannot be resolved(used as imports in main class)


</resources>

<application-desc
     name="Example"
     main-class=
       "Launch"
     width="300"
     height="300">
</application-desc>

<security>
 <all-permissions/>
</security>

<offline-allowed />

<update check="background"/>

</jnlp>          

除了 MyJar.Jar 中的类,我得到所有类的无类定义 excwption。

4

0 回答 0