this.addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent evt) {
        exitedMenuItemActionPerformed(null);
      }
});
不关闭就不要exit

解决方案 »

  1.   

    setExtendedState
    public void setExtendedState(int state)
    Sets the state of this frame. The state is represented as a bitwise mask. 
    NORMAL 
    Indicates that no state bits are set. 
    ICONIFIED 
    MAXIMIZED_HORIZ 
    MAXIMIZED_VERT 
    MAXIMIZED_BOTH 
    Concatenates MAXIMIZED_HORIZ and MAXIMIZED_VERT. 
    Note that if the state is not supported on a given platform, nothing will happen. The application may determine if a specific state is available via the java.awt.Toolkit#isFrameStateSupported(int state) method. 
    Parameters:
    state - a bitwise mask of frame state constants
    Since: 
    1.4 
      

  2.   

    setDefaultCloseOperation
    public void setDefaultCloseOperation(int operation)
    Sets the operation that will happen by default when the user initiates a "close" on this frame. You must specify one of the following choices: DO_NOTHING_ON_CLOSE (defined in WindowConstants): Don't do anything; require the program to handle the operation in the windowClosing method of a registered WindowListener object. 
    HIDE_ON_CLOSE (defined in WindowConstants): Automatically hide the frame after invoking any registered WindowListener objects. 
    DISPOSE_ON_CLOSE (defined in WindowConstants): Automatically hide and dispose the frame after invoking any registered WindowListener objects. 
    EXIT_ON_CLOSE (defined in JFrame): Exit the application using the System exit method. Use this only in applications. 
    The value is set to HIDE_ON_CLOSE by default. Note: When the last displayable window within the Java virtual machine (VM) is disposed of, the VM may terminate. See AWT Threading Issues for more information. 
    Parameters:
    operation - the operation which should be performed when the user closes the frame 
    Throws: 
    IllegalArgumentException - if defaultCloseOperation value isn't one of the above valid values 
    SecurityException - if EXIT_ON_CLOSE has been specified and the SecurityManager will not allow the caller to invoke System.exit
      

  3.   

    如果你用awt.Frame而不是swing.JFrame那么默认就是关不掉的
      

  4.   

    addWindowListener(new WindowAdapter()
            {
                public void windowClosing( WindowEvent e )
                {
                        //to do here
                }
            } );
      

  5.   

    addWindowListener(new WindowAdapter()
            {
                public void windowClosing( WindowEvent e )
                {
            int n = JOptionPane.showConfirmDialog( this,
                    "确认退出",
                    "something",
                    JOptionPane.YES_NO_OPTION );        if ( n == JOptionPane.YES_OPTION )
            {
                System.exit( 0 );
            }
                }
            } );
      

  6.   

    有些IDE自动为JFrame加上一句 
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);把它去掉咯~~
      

  7.   

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JFrame.EXIT_ON_CLOSE这个常量是关闭的,还有个不关闭的想不起来了,如果不写还是可以关闭的
    所以要写
    不知道这个方法可以不?