public class CardLayout_1 {
public static void main(String args[]) {
new CardLayout_1().go();
}
public void go() {
final Frame f = new Frame("CardLayout演示");
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
f.setVisible(false);
f.dispose();
System.exit(0);
}
});
final Frame f1 = f;
for (int i = 1; i <= 5; i++) {
Button b = new Button("Button " + i);
b.setSize(100, 25);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
CardLayout cl = (CardLayout) f1.getLayout();
cl.next(f1);
}
});
f.add(b, "button" + i);
}
f.setVisible(true);
}
}
谁能给解释下这个卡片布局到底是怎么运行的 希望有更好的例子可以借鉴作者: 张华廷 时间: 2012-6-25 09:48
public class CardLayout_1 {
public static void main(String args[]) {
new CardLayout_1().go();
}
public void go() {
final Frame f = new Frame("CardLayout演示");
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
f.setVisible(false);
f.dispose();
System.exit(0);
}
});