2014-03-05 2 views
-2

"확인"또는 "취소"를 클릭하면 닫힙니다. 어떤 코드를 추가해야합니까?JOptionPane 닫기

rightbutton = new JButton("Right."); 
add(rightbutton); 
rightbutton.addActionListener(
    new ActionListener(){ 
     public void actionPerformed(ActionEvent event){ 
      //what do we want to happen when we 
      //click the button 
      final ImageIcon icon = new ImageIcon("C:\\Users\\Scr3am\\Desktop\\paypal.jpg"); 
      JOptionPane.showOptionDialog(null, 
       "Congratulations, you clicked the button.", 
       "Congrats", JOptionPane.DEFAULT_OPTION, 
       JOptionPane.INFORMATION_MESSAGE, null, 
       new Object[] { panel }, icon); 
+0

아닌 다운 유권자하지만, 더 나은 도움을 생성하고 [최소한의 예제 프로그램]을 게시 고려 (http://stackoverflow.com/help/mcve). 자세한 내용은 링크를 확인하십시오. –

+1

[이전 질문] (http://stackoverflow.com/questions/22186026/imageicon-help-close-a-joptionpane)의 답을 따르지 않았습니다. 당신의 주장은 여전히 ​​틀리다. –

+1

@ peeskillet의 정보와 당신의 대답이 부족해, 이제 나는 유권자 다. –

답변

-1

확인을 클릭하면 JOptionPane이 자동으로 닫히지 만 System.exit (0)을 추가하십시오. actionPeformed 메소드에 전달합니다.

예를 들어

rightbutton = new JButton("Right."); 
add(rightbutton); 
rightbutton.addActionListener(
    new ActionListener(){ 
     public void actionPerformed(ActionEvent event){ 
      //what do we want to happen when we 
      //click the button 
      final ImageIcon icon = new ImageIcon("C:\\Users\\Scr3am\\Desktop\\paypal.jpg"); 
      JOptionPane.showOptionDialog(null, 
       "Congratulations, you clicked the button.", 
       "Congrats", JOptionPane.DEFAULT_OPTION, 
       JOptionPane.INFORMATION_MESSAGE, null, 
       new Object[] { panel }, icon); 
       System.exit(0);