title: How to use CardLayout with Multiple JPanels?
body: <p>The first screen is 2 JPanels split using JSplitPane. How do I switch to another screen that is set up the same. I tried putting the first 2 JPanels into a panel container but that doesn't work. Then I tried to just leave them seperate without a container but then only the second bottom panel showed up. How to use cardLayout to switch between two formatted Panels. If three is another way to do this then please tell because CardLayout is a little too difficult to use when all the panels have to be formatted a certain way.</p>
  
  <pre><code>public class Quizlet extends JFrame implements ActionListener  {
  
  public JPanel Container, FTop, FBottom,QTop,QBottom;
  public JScrollPane Scroll;
  public JSplitPane FirstSplit,QuesSplit,FinalSplit;
  public JTextArea Text;
  public JButton Start, Next, Finish;
  public JTextField Answer;
  public JLabel Hello,Ans;
  CardLayout Switch = new CardLayout();
  
  
  public Quizlet () {
  
      Container = new JPanel();   
      Container.setLayout(Switch);
      Container.add(FTop, null);
      Container.add(FBottom,null);
      Switch.show(FTop,null);
      Switch.show(QBottom, null);
  
  
      FTop = new JPanel(new BorderLayout());
  
  
      Hello = new JLabel("Please Click start to begin");
      FTop.add(Hello, BorderLayout.CENTER);
  
      FBottom = new JPanel(new BorderLayout());
  
  
      Start = new JButton("Start Session");
      Start.addActionListener(this);
  
      FBottom.add(Start,BorderLayout.CENTER);
  
      FirstSplit = new JSplitPane();
      FirstSplit.setTopComponent(FTop);                  // at the top we want our "topPanel"
      FirstSplit.setBottomComponent(FBottom); 
  
      add(FirstSplit);
      FirstSplit.setOrientation(JSplitPane.VERTICAL_SPLIT);  
      FirstSplit.setDividerLocation(200);                    
      FirstSplit.setTopComponent(FTop);                  
      FirstSplit.setBottomComponent(FBottom); 
  
      //Second Screen top component
  
      QTop = new JPanel(new GridBagLayout());
      GridBagConstraints c = new GridBagConstraints();
  
      Ans = new JLabel("Answer");
      c.gridx=0;
      c.gridy=0;
      QTop.add(Ans, c);
  
  
      Answer = new JTextField(12);
      c.gridx=0;
      c.gridy=1;
      QTop.add(Answer, c);
      //Second Screen Bottom Component
      QBottom = new JPanel(new BorderLayout());
      Next = new JButton("Next Question");
      QBottom.add(Next,BorderLayout.CENTER);
  
      //Second screen Split
      QuesSplit = new JSplitPane();
      QuesSplit.setTopComponent(QTop);                  
      QuesSplit.setBottomComponent(QBottom); 
  
      add(QuesSplit);
      QuesSplit.setOrientation(JSplitPane.VERTICAL_SPLIT);  
      QuesSplit.setDividerLocation(200);                    
      QuesSplit.setTopComponent(QTop);                  
      QuesSplit.setBottomComponent(QBottom); 
  
  
  
      setSize(500,500);
      setVisible(true);
      setTitle("The Quiz");
      setDefaultCloseOperation(EXIT_ON_CLOSE);
      pack();
  
  
  }
  public void actionPerformed (ActionEvent e) {
      if(e.getSource()==Start) {
          Switch.show(QTop, null);
          Switch.show(QBottom, null);
      }
  }
  
      public static void main(String[] args) {
          javax.swing.SwingUtilities.invokeLater(new Runnable() {
  
              @Override
              public void run() {
                  Quizlet show = new Quizlet();
              }
          });
      }
  }
  </code></pre>