简体   繁体   中英

Application exits on closing of Jframe in java swing in netbeans 7.0

i am actually developing GUI application whwn i run this application a login window comes i have a button on it when after successful login i have MDI application form i have menu in that in menu i have menu items when i click menu items Jframe opens upto here i am haing no problem

but when i close Jframe form entire application exits

LOGIN FORM Code


public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Login().setVisible(true);
            }
        });

BUTTON CODE

 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
         NewMDIApplication n = new NewMDIApplication();
         n.show();
         this.setVisible(false);


    }  

MDIApplication form code

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
        IVITEM i = new IVITEM();---- this is that form that opens inside the MDI appliaction
        i.show();
    }      

in the IVITEM class add this code

this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

and in the main menu in main window add menu item "exit" and in it's action use

System.exit(0);

this will close all child windows

在JFrame属性面板中,将defaultCloseOperation设置为DISPOSE

Your login form is behaving as a dialog and so shouldn't be a JFrame at all but rather a dialog window such as a JDialog, and what's more, should be one that is modal to the main application window (which is likely a JFrame). Many don't realize (and I don't know if this includes you or not) that JDialogs can hold complex GUIs, as complex as any held by a JFrame.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM