开发者

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 ha开发者_如何学运维ndling 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


in the JFrame properties panel, set the defaultCloseOperation to 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜