I am working on a simple 2D game in Java.
I want the game to have an opening screen, instructions screen, and the screen with the game itself.
From the opening screen the user presses buttons to get to the instructions screen or to the game screen. From the instructions the user should be able to get back to the opening screen. When a game is finished, the user is automatically sent back to the opening screen.
I want all of this to happen in the same JFrame
. Each screen should be a class that extends JPanel
.
What would be the best way to do that? I thought of making a method inside the Main class (the one with the main()
method), the switches screens and can be called from anywhere in the program.
But how will this method switch screens? What would be the best way to replace the JPanels?
Thanks a lot