0

This is my main panel where I'm trying to change between multiple other JPanels by clicking a JButton called "next", but when I click on the JButton nothing happens. The HomePanel stays in place the whole time.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class JCAPanel extends JPanel
{
  private HomePanel homeP;
  private ChoicePanel choiceP;
  private JButton next, quit;
  int x;
  public JCAPanel()
{
  x = 0;
  setLayout(new BorderLayout());

  homeP = new HomePanel();

  JPanel subpanel = new JPanel(new BorderLayout());
  next = new JButton("Next");
  next.addActionListener(new ListenerNext());
  quit = new JButton("Quit");
  quit.addActionListener(new ListenerQuit());
  subpanel.add(next, BorderLayout.EAST);
  subpanel.add(quit, BorderLayout.WEST);

  add(subpanel, BorderLayout.SOUTH);
  add(homeP, BorderLayout.CENTER);
}
public class ListenerNext implements ActionListener
{
   public void actionPerformed(ActionEvent e)
   {
      x++;
      if(x == 1)
      {
         choiceP = new ChoicePanel();
         add(choiceP, BorderLayout.CENTER);
      }
   }
}

0 Answers0