开发者

Java Swing UI Changing Method

开发者 https://www.devze.com 2022-12-25 01:15 出处:网络
I would like to use Swing to program a simple learning game. I am wo开发者_Go百科ndering what would be best way to switch between UI screens.

I would like to use Swing to program a simple learning game.

I am wo开发者_Go百科ndering what would be best way to switch between UI screens.

For example, I would have a screen for the Main Menu, and then when the user presses a button on that screen, I would swap out the whole screen for a completely different one.

Then, arbitrary screens can be swapped in at any moment, and all of their event handlers would be reactivated while the inactive screen's event handlers will be deactivated.

What type of Swing component/control would I use for each of the 'screens'. Is this even doable?


You can consider using CardLayout for that purpose.

Each 'screen' can be made as a separate panel. Then you need a container-panel with card layout. And you'll add all screens to that panel. Switching between cards is easy, it's demonstrated in the linked tutorial.


You could also use JTabbedPane so each screen is connected with one button :-)


You probably don't need to reactivate listeners (although the "business" model end of things might want to check state). Simple switch panels.

0

精彩评论

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

关注公众号