So I have this swing GUI and I'm trying to figure out how to switch panels/screens when the button is clicked but right now the first panel goes away but the second one won't show up.
public class GUI {
static JFrame mainFrame = new JFrame();
public GUI () {
openLoginScreen();
}
private static void openLoginScreen() {
JPanel loginPanel = new JPanel();
JButton newAccountButton = new JButton ("Create New Account");
newAccount.addActionListener (new ActionListener () {
public void actionPerformed (ActionEvent e) {
mainFrame.remove(titlePanel);
mainFrame.repaint();
openNewAccountScreen();
}
} );
loginPanel.add(newAccountButton);
mainFrame.add(loginPanel);
}
private static void openNewAccountScreen() {
JPanel newAccount = new JPanel();
mainFrame.add(newAccount);
}
}
I've tried just removing one panel and adding another or repainting after doing both or repainting in between and nothing seems to be working :( Obviously I left out a bunch of other stuff that are in the program but this is basically what the problem is. Any help would be very appreciated or tips in general. I'm still fairly new to swing. Thx :D