Design pattern for window management in a Java Swing app

Posted by Lord Torgamus on Programmers See other posts from Programmers or by Lord Torgamus
Published on 2011-01-24T21:38:51Z Indexed on 2011/01/31 7:33 UTC
Read the original article Hit count: 471

Filed under:
|
|
|

I've just started creating my very first little Java Swing app. When the program opens, it brings up a single, simple window with a label and a couple buttons. Clicking one of those buttons is supposed to wipe out the welcome screen and replace it with a totally different panel.

I'm not sure what the best way to create that functionality is. One method would be to pass my JFrame as an argument into... just about every other component, but that feels hacky to me. Or, there's making each panel double as an action listener, but that doesn't seem right, either.

Is there a design pattern I should be applying here? "Replace the contents of the main — and only — window" must be a reasonably common operation. A name for the pattern would be enough; I can use Google on my own from there. (I wouldn't say no to a longer explanation, though.)

© Programmers or respective owner

Related posts about java

Related posts about design-patterns