3

I'm having trouble getting my program to switch JPanels when I press the nextButton using card layout.

This is what it looks like:

I want the program to switch to the "customerSearch" JPanel. It has the Card Name & name of Card2. panelContainer has a card layout. What am I doing wrong?

public class Gui {
private JPanel panelContainer;
private JPanel takeoutOption;
private JPanel customerSearch;
private JButton nextButton;

private CardLayout cl = (CardLayout)panelContainer.getLayout();


public Gui() {

    nextButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            cl.show(panelContainer, "Card2");
        }
    });
}
curious
  • 1,504
  • 5
  • 18
  • 32
  • 1
    I was able to fix the problem. What I found was that my code was correct. Instead, the problem was that the button did not work using the preview feature on the form. – user3875320 Sep 11 '17 at 23:53

0 Answers0