I have been programming in Android and I switch between specific screens using intents. I have always wondered how to do this in Java, when I click a button switch to a different screen. Is there a way to specify multiple JFrames
or would I have to delete all of the objects off one frame and then add some?
Asked
Active
Viewed 1,757 times
3
-
@Op. I removed the android related tags since your question is a Swing question, and not an Android question (I did also add the Swing tag). – Kaj Jul 25 '11 at 14:30
-
You can have multiple JFrames in a Swing application, and you can bring different frames to front, and/or hide certain frames depending on what the user does. How you do that depends a bit on what architecture you are using, but you should look into the MVC architecture, and also read a bit about IOC since that usually makes it easier to implement MVC. – Kaj Jul 25 '11 at 14:32
1 Answers
7
You can use CardLayout
for "switching content". See How to use CardLayout.
And instead of Intents in Android, you should use Action
in Java Swing. See How to use Actions.

Jonas
- 121,568
- 97
- 310
- 388
-
See also [CardLayout Demo.](http://stackoverflow.com/questions/5665156/calling-awt-frame-methods-from-subclass/5786005#5786005) for an example. – Andrew Thompson Jul 25 '11 at 14:35