Answer the question
In order to leave comments, you need to log in
How to implement switching between panels in java?
I'm trying to make an application that opens one page when launched, and when a button is clicked, it switches to another page.
Main class:
public class Main {
public static Frame frame;
public static JPanel[] panels = {new Panel(), new myAction()};
public static int panelNumber = 0;
public static void main(String[] args) {
frame = new Frame();
frame.add(panels[panelNumber]);
}
}
class Panel extends JPanel {
public Panel() {
JButton btn = new JButton("Start");
add(btn);
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
Main.panelNumber = 1;
}
});
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question