📄 mycardlayout.java
字号:
import java.awt.*;import java.awt.event.*;public class MyCardLayout extends MouseAdapter{ private Frame f; private Panel p1, p2, p3, p4, p5, p6; private Label l1, l2, l3, l4, l5, l6; private CardLayout myCard; public static void main(String[] args){ MyCardLayout that = new MyCardLayout(); that.go(); } private void go(){ f = new Frame("CardLayout Example !"); myCard = new CardLayout(); f.setLayout(myCard); p1 = new Panel(); p2 = new Panel(); p3 = new Panel(); p4 = new Panel(); p5 = new Panel(); p6 = new Panel(); l1 = new Label("This is the first Card"); l2 = new Label("This is the second Card"); l3 = new Label("This is the third Card"); l4 = new Label("This is the fourth Card"); l5 = new Label("This is the fifth Card"); l6 = new Label("This is the sixth Card"); p1.add(l1); p1.setBackground(Color.yellow); p1.addMouseListener(this); p2.add(l2); p2.setBackground(Color.red); p2.addMouseListener(this); p3.add(l3); p3.setBackground(Color.green); p3.addMouseListener(this); p4.add(l4); p4.setBackground(Color.magenta); p4.addMouseListener(this); p5.add(l5); p5.setBackground(Color.white); p5.addMouseListener(this); p6.add(l6); p6.setBackground(Color.cyan); p6.addMouseListener(this); f.add(p1, "First"); f.add(p2, "Second"); f.add(p3, "Third"); f.add(p4, "Fourth"); f.add(p5, "Fifth"); f.add(p6, "Sixth"); myCard.show(f, "First"); f.setSize(300, 200); f.show(); } public void mouseClicked(MouseEvent e){ myCard.next(f); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -