繁体   English   中英

小程序上的JOptionPane,accessEventQueue accessControlException

[英]JOptionPane on applet, accessEventQueue accessControlException

我编写了一个生成测验小程序的应用程序。 我找不到一种可移植的方式来自动签名生成的applet,因此无法对其进行签名。 但是据我所知,这段简单的代码不需要对Applet进行签名,但是它在Linux上引发了有关“ accessEventQueue”的accessControlException。 我在IceTea7,OpenJDK7上运行它,我在Chrome和Opera上都尝试过。

System.out.println("This will display...");

int r = JOptionPane.showConfirmDialog(null,"End the quiz now?",
    "Quiz",
    JOptionPane.YES_NO_OPTION,                  
    JOptionPane.INFORMATION_MESSAGE);

System.out.println("This won't...");

冲浪一点,我发现这个关于IcedTea的错误信息。 我自己在Windows上尝试过该applet,并且在该处未引发任何异常。

如果发现的确是一个错误,是否有任何解决方法,或者我将必须实现自己的确认对话框...?

有什么方法可以弹出JOptionPane对话框而不干扰AWT事件队列?

正如我从开发人员那里听到的那样,这是一个实际的错误。

这是我天真的确认对话框的实现,可以节省一些编码时间:

public class ConfirmDialog implements ActionListener {
    JFrame main;
    ConfirmCallback callback;

    public ConfirmDialog(String msg,String[] opts, ConfirmCallback lc) {
        this(msg,"Selection",opts,lc);
    }

    public ConfirmDialog(String msg,String title ,String[] opts,  ConfirmCallback lc) {
        main = new JFrame();
        main.setTitle(title);
        this.callback = lc;
        main.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        GridBagConstraints gbc = new GridBagConstraints();
        GridBagLayout layout = new GridBagLayout();

        JPanel panel = new JPanel();
        panel.setLayout(layout);
        panel.setBorder(BorderFactory.createEmptyBorder(5,5,5,5));
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.gridx = 0; gbc.gridy =0;
        gbc.gridwidth = opts.length; gbc.gridheight = 1;
        gbc.insets = new Insets(3,3,3,3);

        JLabel mainLabel = new JLabel(msg);

        layout.setConstraints(mainLabel, gbc);
        panel.add(mainLabel);

        gbc.gridy = 1;
        gbc.gridwidth= 1;

        int cnt = 0;
        for (String s: opts) {
            JButton submitButton = new JButton(s);
            submitButton.setActionCommand(Integer.toString(cnt++));
            submitButton.addActionListener(this);   
            gbc.gridx = cnt;
            layout.setConstraints(submitButton, gbc);
            panel.add(submitButton);
        }
        main.add(panel);
        main.pack();
        main.setLocationRelativeTo(null);
        main.setVisible(true);

    }

    public ConfirmDialog() {}

    @Override
    public void actionPerformed(ActionEvent e) {
        callback.run(Integer.decode(e.getActionCommand()));
        main.dispose();
    }

    public void Test() {
        ConfirmCallback cb = new ConfirmCallback(){
            @Override
            public void run(int arg) {
                JOptionPane.showMessageDialog(null, "The user just entered: "+arg);
            }
        };
        new ConfirmDialog("Please choose",new String[] {"a","b","c"},cb);
    }

    public static void main(String args[]) {
        new ConfirmDialog().Test();
    }
}

这是它使用的回调:

public abstract class ConfirmCallback {
    public abstract void run(int arg);
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM