简体   繁体   中英

Moving from one JFrame to another

In a package in Netbeans I created two JFrame Forms, first one is Login, second is, mainProgram, after the successful log in, I use the following way to "close" the Login frame and open the main program frame.

mainProgram m=new mainProgram();
m.setVisible(true);
setVisible(false); //to hide the log in frame

Is this the correct way? Isn't it wrong if these two separated classes are hidden instead of being closed? are these one process or two different processes? if there's a better way then what is it?

thanks..

Is this the correct way?

Yes, this should be fine.

isn't it wrong if these 2 separated classes are hidden instead of being closed?

The ideal is dispose of your unused forms (such as the login form when not needed any more)

are these 1 process or 2 different processes?

These will run on the same process

In a package in Netbeans I created 2 JFrame Forms, first one is Login, second is, mainProgram, after the successful log in, I use the following way to "close" the Login frame and open the main program frame.

use CardLayout , after correct login you can to switch the GUI to next Card and/or with change for JFrame Dimmnsion on the screen too,

in my opinion the more correct way is to use another class, like Launcher, which will have the entry point (main method). Make the login window as a modal JDialog, and set DISPOSE_ON_CLOSE as a value of default close operation . The class of dialog should contain a method to inform a user really logged in. After the login dialog is closed, show the main frame

loginDialog.setVisible(true);
if (loginDialog.isLoggedIn())
    mainFrame.setVisible(true);

Try this...

  1. The approach you used to hide and un-hide is fine, but will be better if dispose is used .

  2. Try applying the Singleton pattern on the classes which govern these JFrames.

  3. And yes they both will be on the same Process .

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