2014-03-05 139 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);