我用的
    public void windowClosing(WindowEvent w){
     int num = JOptionPane.showConfirmDialog(f,"确定要退出吗?","提示",JOptionPane.OK_CANCEL_OPTION);
     if(num==0){
     System.exit(0);
     }
    }
按了确定后可以正常退出结束程序...但是如果按了取消程序是退出了,但没结束..我想按了取消后,程序接着运行..
请问要怎么搞??谢谢

解决方案 »

  1.   

    如你所写的,点了取消之后程序是会继续进行的啊。
    public static void main(String[] args) {
    final Frame f = new Frame();
    f.setSize(100,100);
    f.addWindowListener(new WindowAdapter() { @Override
    public void windowClosing(WindowEvent e) {
    int num = JOptionPane.showConfirmDialog(f, "确定要退出吗?", "提示",
    JOptionPane.OK_CANCEL_OPTION);
    if (num == 0) {
    System.exit(0);
    }
    }
    });
    f.setVisible(true);
    }
      

  2.   

    public void  windowClosing(WindowEvent   e)   {   
              int   response;   
              response=JOptionPane.showConfirmDialog(null,"真的要退出吗?");   
              if(response==JOptionPane.YES_OPTION)   
                  {   
                    System.exit(0);   
                  }
              else
                  return;
      }
      

  3.   

    要先加入frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);   
      

  4.   

    JAVA技术交流与学习:45633778技术交流,共同进步!!
      

  5.   

    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);       
      

  6.   

    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
            addWindowListener(new WindowAdapter(){
             public   void     windowClosing(WindowEvent       e)       {       
                    int       response;       
                    response=JOptionPane.showConfirmDialog(null,"真的要退出吗?");       
                    if(response==JOptionPane.YES_OPTION)       
                            {       
                                System.exit(0);       
                            }
                    else
                     return;
             }
            });
    我这样试过了,可以啊