所以我有这个摇摆 GUI,我试图弄清楚如何在单击按钮时切换面板/屏幕,但现在第一个面板消失了,但第二个面板不会出现。
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);
}
}
我尝试只是删除一个面板并添加另一个或在完成两者或两者之间重新粉刷后重新粉刷,但似乎没有任何效果:(显然,我遗漏了程序中的一堆其他东西,但这基本上就是问题所在。任何帮助将不胜感激或一般提示。我对秋千还是很陌生的。谢谢:D
我认为您需要添加重新验证或重新绘制