title: Adding panel to container with Java's swing
body: <p>I have made two panels and then added in third panel. How can I add a panel to show up on screen?</p>
  
  <p>Here is my current code:</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  
  public class LibraryFront {
  
  public static void main(String[] args)
  {
  
      JFrame f1 = new JFrame();
      JPanel cards;
      final String BUTTONPANEL = "Card with JButtons";
      final String TEXTPANEL = "Card with JTextField";
  
      JPanel card1 = new JPanel();
      JPanel card2 = new JPanel();
  
      // Create the panel that contains the "cards".
      cards = new JPanel(new CardLayout());
      cards.add(card1, BUTTONPANEL);
      cards.add(card2, TEXTPANEL);
  
      Container c = getContentPane(); //this gives error
  }
  </code></pre>