简体   繁体   中英

Java Swing - Multiple control sets in one window

Is it possible to create something like a loading phase (contains progressbar and label etc.) then after loading is done switch to next phase with different controls like button etc. without creating a new Window for each of the phases? I know I could probably do this using panels and changing their visibility but if they all overlaped it would be really hard to add or edit the controls. I want to create a game and it would be really annoying if a new window opened almost everytime user did something. (example Main menu -> Shop -> Back to main menu etc.)

There are two ways to do this: Static and dynamic

The static way is easier, and you can accomplish it using a CardLayout. The dynamic way would require you to create methods for each screen change, which would clear all previous content and insert the appropriate controls.

http://docs.oracle.com/javase/tutorial/uiswing/layout/card.html

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