📄 mycardlayout.java
字号:
package sample;
import java.awt.*;
import java.awt.event.*;
public class MyCardLayout {
public static void main(String args[]) {
new MyCardLayout().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);
}
});
f.setSize(300, 100);
f.setLayout(new CardLayout());
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);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -