title: JFrame and JPanels
body: <p>I'm making a GUI, which allows me to choose one of few options, which have more options(buttons). I'm inexperienced at Java and have some problem with it.  </p>
  
  <p>Why <code>this.dispose()</code> doesn't open new <code>JPanel</code> after clicking <code>Button11</code>? How I can open new <code>JPanel</code> exactly <code>Panel11</code>? Could you give me some advice?</p>
  
  <pre><code>class Panel1 extends JPanel
  {
  private Frame frame;
  private JButton backButton;
  private JButton Button11;
  private JButton Button12;
  private JButton Button13;
  
  public Panel1(Frame f)
  {
  frame=f;
  
  setPreferredSize(new Dimension(500,500));
  backButton=new JButton("Back");
  Button11=new JButton("Z warunkami atmosferycznymi");
  Button12=new JButton("Z kontrolą ruchu lotniczego");
  Button13=new JButton("Z uszkodzeniem/awarią");
  
  add(new JLabel("Podczas lotu"));
  add(backButton);
  add(Button11);
  add(Button12);
  add(Button13);
  
  backButton.addActionListener( new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e){
      frame.back(); }
                                }
  );
  
  Button11.addActionListener( new ActionListener () {
      public void actionPerformed(ActionEvent e) {
      Panel11 panel = new Panel11();
      panel.setVisible(true);
      panel.setLocationRelativeTo(null);
      this.dispose();
         }
  }
  );
      }
  }
  
  class Panel11 extends JPanel
  {
  
  private Frame frame;
  private JButton backButton;
  
  public Panel11(Frame f)
  {
  frame=f;
  
  setPreferredSize(new Dimension(200,500));
  backButton=new JButton("Back");
  add(new JLabel("Podczas rotacji"));
  add(backButton);
  backButton.addActionListener( new ActionListener()
                                {
                                  @Override
                                public void actionPerformed(ActionEvent e)
                                  {
                                    frame.back();
                                  }
                                }
   );  
  }
  }
  
  class Frame extends JFrame
  {
  
  private JPanel main;
  private JButton button1;
  private Panel1 panel1;
  
  
  public Frame()
  {
  super("Algorytm przydziału kodów opóźnień");
  
  main=new JPanel();
  main.setPreferredSize(new Dimension(400,200));
  panel1=new Panel1(this);
  
  button1=new JButton("Podczas lotu");
  button1.addActionListener(new ActionListener()
                            {
                              @Override
                              public void actionPerformed(ActionEvent e)
                              {
                                update(panel1);
                              }
                            }
  );
  
  main.add(button1);
  
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  add(main);
  pack();
  setResizable(true);
  setVisible(true);
  }
  
  public void back()
  {
  update(main);
  }
  
  private void update(JPanel panel)
  {
  remove(panel1);
  remove(main);
  add(panel);
  pack();
  panel.setVisible(true);
  setVisible(true);
  }
  }
  
  
  public class Main
  {
  public static void main(String[] args)
  {
  new Frame();
  }
  }    
  </code></pre>