import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CardLayoutTest{
public static void main(String[] args){
CardFrame cf = new CardFrame();
cf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
cf.setVisible(true);
}
}
class CardFrame extends JFrame implements ActionListener{
private static final int WIDTH = 400;
private static final int HEIGHT = 300;
private JPanel jpCenter;
private JPanel jpSouth;
private JButton jbFirst;
private JButton jbNext;
private JButton jbLast;
private JButton jbShow1;
private JButton jbShow2;
private JButton jbShow3;
private JButton jbShow4;
private JButton jbShow5;
private CardLayout cl;
public CardFrame(){
this.setTitle("CardLayout布局示例");
this.setSize(WIDTH,HEIGHT);
jpCenter = new JPanel();
jpSouth = new JPanel();
this.add(jpCenter, BorderLayout.CENTER);
this.add(jpSouth, BorderLayout.SOUTH);
jbFirst = new JButton("First");
jbNext = new JButton("Next");
jbLast = new JButton("Last");
jpSouth.add(jbFirst);
jpSouth.add(jbNext);
jpSouth.add(jbLast);
jbFirst.addActionListener(this);
jbNext.addActionListener(this);
jbLast.addActionListener(this);
jbShow1 = new JButton("按钮一");
jbShow2 = new JButton("按钮二");
jbShow3 = new JButton("按钮三");
jbShow4 = new JButton("按钮四");
jbShow5 = new JButton("按钮五");
jpCenter.add(jbShow1);
jpCenter.add(jbShow2);
jpCenter.add(jbShow3);
jpCenter.add(jbShow4);
jpCenter.add(jbShow5);
cl = new CardLayout();
jpCenter.setLayout(cl);
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == jbFirst){
cl.first(jpCenter);
}
if(e.getSource() == jbNext){
cl.next(jpCenter);
}
if(e.getSource() == jbLast){
cl.last(jpCenter);
}
}
}