Java Swing: how to implement the login screen before displaying the JFrame?

I try to make a small game. First, a simple login screen will be displayed to players. They can enter their names (I need to store their game status information later) and let them choose a difficulty level. Once the player clicks the play button, the main game screen will be displayed I also want to allow players to navigate (hopefully they are quite large) the trophy collection, which will also be a new screen in their view

So far, I have a main game window, grid layout and a game, its works (for me) Now I want to add the above functions

What should I do? I don't think I want to go to multiple JFrame routes, because I just want to see one icon in the taskbar at a time (or setting their visibility to false will also affect the icons?) Can I make and destroy things like layouts or panels

What choice do I have? How do I control what is displayed? Especially for my novice skills?

Solution

A simple modal dialog, such as jdialog, should be good here When the dialog box is called, the main GUI of JFrame may not be visible, and then it is set to visible after the dialog box is completed (assuming successful login) If the dialog box is modal, you will know exactly when the user closes the dialog box, because the code will continue after the line calling setvisible (true) on the dialog box Note that the GUI held by jdialog can be as complex and rich as JFrame

Another option is to use a GUI / JFrame in the main GUI through CardLayout, but swap views (jpanels) This works well and is easy to implement See CardLayout tutorial for more information

Oh, welcome to stackoverflow com!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>