title: Java: CardLayout switching between cards
body: <p>I've got class 'Frame' which extends <code>JFrame</code> and separetad <code>JPanels</code>: <code>MainMenu</code> and <code>SinglePanel</code>
  I am using <code>CardLayout</code>, but I've got problem when switching back to panels using  <code>buttonSingle</code> and <code>powrot</code> buttons. So my question is how can I change/swap between cards using these buttons?</p>
  
  <p>My <code>Frame</code> class:</p>
  
  <pre><code>    public class Frame extends JFrame{
  
      CardLayout cl = new CardLayout();
      final MainMenu menuPanel = new MainMenu();
      final SinglePanel singlePanel = new SinglePanel();
  
      public Frame(){
  
          setLayout(cl);
          add(menuPanel,"menu");
          add(singlePanel,"single");
  
  
          setSize(200, 200);
          setLocationRelativeTo(null);
          setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
          setVisible(true);
          setEnabled(true);
          swapView("menu");
  
      }
  
      public void swapView(String view){
          cl.show(getContentPane(),view);
      } 
  }
  </code></pre>
  
  <p>my <code>MainMenu</code> class:</p>
  
  <pre><code>public class MainMenu extends JPanel{
  
  
      public MainMenu(){
  
  
          setLayout(new BoxLayout(this , BoxLayout.Y_AXIS));
          add(Box.createVerticalGlue());
  
          JButton buttonSingle = new JButton("Single");     
          buttonSingle.setAlignmentX(Component.CENTER_ALIGNMENT);
          buttonSingle.addActionListener(new ActionListener(){
  
              @Override
              public void actionPerformed(ActionEvent e) {
  
              }
          });
          add(buttonSingle);
          add(Box.createVerticalGlue());
          JButton buttonMulti = new JButton("Multiplayer"); 
          buttonMulti.setAlignmentX(Component.CENTER_ALIGNMENT);
          buttonMulti.addActionListener(new ActionListener(){
  
              @Override
              public void actionPerformed(ActionEvent e) {
                  throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
              }
          });
          add(buttonMulti);
          add(Box.createVerticalGlue());
          JButton buttonExit = new JButton("Wyjście");  
          buttonExit.setAlignmentX(Component.CENTER_ALIGNMENT);
          buttonExit.addActionListener(new ActionListener(){
  
              @Override
              public void actionPerformed(ActionEvent e) {
                  System.exit(0);
              }});
              add(buttonExit);
              add(Box.createVerticalGlue());                        
          }
      }
  </code></pre>
  
  <p>my <code>SinglePanel</code> class</p>
  
  <pre><code>public class SinglePanel extends JPanel{
  
      SinglePanel(){
          setLayout(new FlowLayout());
  
          JButton powrot = new JButton("Wróć do menu");        
          powrot.addActionListener(new ActionListener(){
  
              @Override
              public void actionPerformed(ActionEvent e) {
  
              }
          });
          add(powrot);
      }
  }
  </code></pre>
  
  <p>Main class:</p>
  
  <pre><code>public class Main {
  
      /**
       * @param args the command line arguments
       */
      public static void main(String[] args) {
          // TODO code application logic here      
  
          /*MainMenu mM = new MainMenu();*/
  
          Frame f = new Frame();
      }
  
  }
  </code></pre>