About to start working with swing for the first time and have a question. What is the best way to change between different views and/or modes in a program?
For example, let's say I create a JPanel that I want displayed when the program is first started. It contains 3 buttons that lets the user select between 3 "modes" of the program. I then take this JPanel instance and add it to the JFame's content pane. (All of the other JFrame settings are set and setVisible is set to true).
When the user starts the program, they see the 3 buttons and are asked to select one. When the user presses a button, I want to get rid of this screen completely and show another JPanel in its place. Then, after the user is done with whatever that option takes them to, they can exit and go back to the main screen (with the 3 buttons).
Is the following the best way to achieve this?
Add action listener for the button that does the following:
1. Remove the "3 button" JPanel from the JFrame's content pane
2. Add new JPanel to JFrame's content pane
Alternatively, could you create instances of JDialog and toggle their visibility?
In short, what is the most efficient way to do this?