這是CardTesting類,我得到IllegalArgumentException:CardLayout的父級錯誤。行cl.show(this,「Panel 2」)拋出一個IllegalArgumentException:CardLayout的父類錯誤。請幫忙! :d我不明白爲什麼我得到IllegalArgumentException:CardLayout的父級錯誤
import java.awt.*;
import javax.swing.*;
public class CardTesting extends JFrame {
CardLayout cl = new CardLayout();
JPanel panel1, panel2;
public CardTesting() {
super("Card Layout Testing");
setSize(400, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(cl);
panel1 = new JPanel();
panel2 = new JPanel();
panel1.add(new JButton("Button 1"));
panel2.add(new JButton("Button 2"));
add(panel1, "Panel 1");
add(panel2, "Panel 2");
setVisible(true);
}
private void iterate() {
try {
Thread.sleep(1000);
} catch (Exception e) { }
cl.show(this, "Panel 2");
}
public static void main(String[] args) {
CardTesting frame = new CardTesting();
frame.iterate();
}
}
您可以附加堆棧跟蹤嗎? – AlexR
這是你的問題嗎? http://stackoverflow.com/questions/12290609/java-cardlayout-show-illegalargumentexception – alessiop86