2012-06-10 4 views
1

퀴즈 애플릿을 생성하는 응용 프로그램을 작성했습니다. 생성 된 애플릿을 자동으로 서명 할 수있는 이식 가능한 방법을 찾을 수 없으므로 서명되지 않았습니다. 하지만 내가 아는 한이 간단한 코드는 애플릿에 서명 할 필요가 없지만 리눅스에서는 "accessEventQueue"에 대한 accessControlException을 던지고 있습니다. IceTea7, OpenJDK7에서 실행 중이므로 Chrome과 Opera에서 모두 시도했습니다.애플릿의 JOptionPane, accessEventQueue accessControlException

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에 버그에 대한 this 정보를 발견했다. 나는 애플릿을 윈도우에서 직접 시도했지만 아무런 예외도 던지지 않는다.

내가 발견 한 것이 실제로 버그 인 경우 해결 방법이 있습니까? 아니면 직접 확인 대화 상자를 구현해야합니까?

AWT 이벤트 대기열을 방해하지 않고 JOptionPane 대화 상자를 팝업 할 수있는 방법이 있습니까?

답변

0

개발자 분들의 의견대로 실제 버그입니다.

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); 
} 

여기에 확인 대화 상자의 내 순진 구현은 당신에게 코딩 시간을 절약 할 수 있어요