import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Win extends JFrame implements ActionListener {
     JPanel jPanel1;
     CardLayout cardLayout1;
     JButton jButton1, jButton2, jButton3, jButton4;
     JButton up,down;
     public Win() {
       setTitle("CardLayout布局应用");
       setLayout(null);
       jPanel1 = new JPanel();
       cardLayout1 = new CardLayout();
       jButton1 = new JButton("第一个按钮");
jButton2 = new JButton("第二个按钮");
jButton3 = new JButton("第三个按钮");
jButton4 = new JButton("第四个按钮");
up = new JButton("上一个");
down = new JButton("下一个");
up.setBounds(10, 140, 80, 25);
down.setBounds(100, 140, 80, 25);
up.addActionListener(this);
down.addActionListener(this);
jPanel1.setBounds(20, 15, 155, 116);
jPanel1.setLayout(cardLayout1);
jPanel1.add(jButton1, "jButton1");
jPanel1.add(jButton2, "jButton2");
jPanel1.add(jButton3, "jButton3");
jPanel1.add(jButton4, "jButton4");
add(jPanel1);
add(up);
add(down);
setBounds(200, 200, 200, 220);
validate();
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==up){
cardLayout1.previous(jPanel1);
}
else if(e.getSource()==down){
cardLayout1.next(jPanel1);
}
}
}
class CardLayout_test{
     public static void main(String args[]) {
          new Win();
     }
}

