How do I go from the login screen to the next screen? JPanel, JFrame?

I have a question about creating graphical applications. I feel like the title of this question is not very accurate, but I couldn't think of a better one.

What's the correct way to create an application? Should I just create one JFrame and then change the panels in that JFrame as needed? Or should I always create a new JFrame and get rid of the old one when moving from one thing to another?

For example, I have a JFrame containing a JPanel that has few text boxes and JLabels. User enters username and password, clicks login button to continue. Should a brand new JFrame appear or create a new JPanel instead of the old JFrame?

+3


source to share


3 answers


Depends, but it's often better if you can reuse the same window. Often you can use JDialog / JOptionPane to handle login. Dialog windows should be more disposable



+4


source


Another way is to use CardLayout if authentication passed, then display JMenuBar with JMenuItems

to access other cards,



+4


source


I recommend using 1 JFrame with JDesktopPane as the "base" of your application.

Then you can output any dialogs or inner frames from the JDesktopPane. This works even if you are not using internal frames.

So, answering your question, I would first build 1 JFrame with JMenubar, JToolbar and JDesktopPane. Then, among other things, I would open up a JDialog with registration fields and a nice splash screen. If it registers ok, you close the dialog and enable the menu bar and toolbar. From there, you keep opening and closing any dialogs or inner frames ...

Hope it helps ...

+1


source







All Articles