views:

96

answers:

3

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

I am wondering 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?

+8  A: 

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.

Roman
+1  A: 

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

Karussell
+1  A: 

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

Tom Hawtin - tackline