Singleton with CardLayout won't show card when another class calls Singleton.instance.show()
- 阅读更多 关于 Singleton with CardLayout won't show card when another class calls Singleton.instance.show()
问题 public class MainWindow extends JPanel { public static MainWindow instance = new MainWindow(); private CardLayout cards = new CardLayout(); public MainWindow() { setLayout(cards); add(new FirstPage(), Pages.FIRST.toString()); add(new SecondPage(), Pages.SECOND.toString()); add(new ThirdPage(), Pages.THIRD.toString()); } public void showPage(Pages page) { cards.show(this, page.toString()); } } the showPage(page); method works fine if I call it in the constructor of MainWindow . But when I try