How to implement switching between panels in java?

Trying to make an app at startup which opens one page, and when you press the button it switches to another page.
Main class:
public class Main {
 public static Frame Frame;
 public static JPanel[] panels = {new Panel(), new myAction()};
 public static int panelNumber = 0;

 public static void main(String[] args) { 
 frame = new Frame();

The panel class:
class Panel extends JPanel { 
 public Panel() {
 JButton btn = new JButton("Start");
 btn.addActionListener(new ActionListener() { 
 public void actionPerformed(ActionEvent arg0) {
 // TODO Auto-generated method stub
 Main.panelNumber = 1; 

Different pages represent different panels. Class second panel is the same only when you click on panelNumber switches back to 0. The problem is that switching between them does not occur. Although if you manually change panelNumber in the Main class, when you start will only appear on the second panel. How can I solve this problem?
June 3rd 19 at 19:24
1 answer
June 3rd 19 at 19:26
Or to manipulate the visibility of the panels, or create/remove panel (possibly here need methods repaint() and revalidate()

Find more questions by tags JavaSwing