I\'m trying to make a game. There\'s several different screens in the game such as a main menu, and the actual game screen. Each of these is a separate jpanel extension. I have
If you want to switch between two panels add those panels into another JPanel and use cardLayout. Then, before adding a JPanel remove the current one. Like this:
parentPanel.removeAll();
parentPanel.repaint();
parentPanel.revalidate();
parentPanel.add(childPanel1);
parentPanel.repaint();
parentPanel.revalidate();
Likewise do the same thing for other child panels.