class Test
{
   public static void main(String[]args)
   {
         MainFrame mf=new MainFrame("文本编辑程序");
         mf.setSize(800,600);
         mf.setLocation(100,100);
         mf.setVisible(true);
         mf.addWindowListener(new WindowAdapter()
          {
             public void windowClosing(WindowEvent e)
             {
                   MainFrame f=new MainFrame(""); 
                                           int s=JOptionPane.showConfirmDialog(f,"你真的要结束吗","结束程序",JOptionPane.YES_NO_CANCEL_OPTION); 
                                           if(s==JOptionPane.YES_OPTION) {System.exit(0);} 
                                                                                                                                                                                                           
             }
          });
   }
}
我在关闭窗口的时候我如果选择了"否"或者"撤消"程序就会退出
请问:这是为什么?怎么还能在点击"否"或者"撤消"时窗口返回原来的样子?
急用?谢谢!!!!!!

解决方案 »

  1.   

    呵呵,我这儿用的Frame试的,是可以的,你看看你的mainframe类吧
    package temp;import java.awt.Frame;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;import javax.swing.JOptionPane;class Test {
    public static void main(String[] args) {
    Frame mf = new Frame("文本编辑程序");
    mf.setSize(800, 600);
    mf.setLocation(100, 100);
    mf.setVisible(true);
    mf.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    Frame f = new Frame("");
    int s = JOptionPane.showConfirmDialog(f, "你真的要结束吗", "结束程序",
    JOptionPane.YES_NO_CANCEL_OPTION);
    if (s == JOptionPane.YES_OPTION) {
    System.exit(0);
    }
    if(s==JOptionPane.NO_OPTION){
    System.out.println("u press no");
    }
    }
    });
    }
    }
      

  2.   

    在命令提示行  怎么正常结束 
    不用CTRL+C命令结束本次运行
      

  3.   

    在  mf.setVisible(true); 前面加下这句:
        mf.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
      

  4.   

    import java.io.*;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;public class Calculator
    {
       public static void main(String[]args)
       {
            Frame mf=new Frame("文本编辑程序");
            mf.setSize(400,300);
            mf.setLocation(100,100);
            mf.setVisible(true);
            mf.addWindowListener(new WindowAdapter()
            {
               public void windowClosing(WindowEvent e)
               {
                    int s=JOptionPane.showConfirmDialog(null,"你真的要结束吗","结束程序",JOptionPane.YES_NO_OPTION);
    if(s==JOptionPane.YES_OPTION) {System.exit(0);} 
               }
            });
       }
    }
      

  5.   

    同意小淘淘
    要加个this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
      

  6.   

    if (s==JOptionPane.YES_OPTION) System.exit(0);
    else return;
    不行吗?
      

  7.   

    你的mainframe肯定有问题,是否加了同样的listener!
      

  8.   

    现在已经不推荐使用System.exit(0);了,因为他会把你运行的其他的全部关掉