Tag: illegalargumentexception cardlayout

Java – CardLayout show()IllegalArgumentException

我有一个CardLayout show方法的问题 所以我宣布我的CardLayout并将其应用到我的JPanel CardLayout cl = new CardLayout(); panel.setLayout(cl); 然后我在CardLayout中添加了2个面板 cl.addLayoutComponent(panel, “menuScreen”); cl.addLayoutComponent(panel1, “gameScreen”); 然后我有一个JButton,当点击时,我显示gameScreen public void mouseClicked(MouseEvent e) { if(e.getSource() == (startGame)) scenechange.show(panel,”gameScreen”); } 唯一的问题是它没有进入我的gameScreen。 它给了我一个llegalArgumentException。 它说“线程中的exception”AWT-EventQueue-0“java.lang.IllegalArgumentException:CardLayout的错误父级”。 提前致谢