import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Insets;
import javax.swing.ImageIcon;
import java.awt.event.*;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
import java.io.*;
/**
* Java中CardLayout布局管理器使用的小例子
*
* @朱
*
*/
public class TestMain2 extends JFrame {
private JPanel pane = null; // 主要的JPanel,该JPanel的布局管理将被设置成CardLayout
private CardLayout card = null; // CardLayout布局管理器
private JPanel p_1 = new JPanel();
private JPanel p_2 = new JPanel();
private JPanel p_3 = new JPanel();
private JPanel p_4 = new JPanel();
private JPanel p_5 = new JPanel();
private JPanel p_6 = new JPanel();
private JPanel p_7 = new JPanel();
private JPanel p_8 = new JPanel();
private JPanel p_9 = new JPanel();
private JPanel p_10 = new JPanel();
private JPanel p_11 = new JPanel();
private JPanel p_12 = new JPanel();
private JPanel p_13 = new JPanel();
private JPanel p_14 = new JPanel();
private JPanel p_15 = new JPanel();
private JPanel p_16 = new JPanel();
private JPanel p_17 = new JPanel();
private JPanel p_18 = new JPanel();
private JPanel p_19 = new JPanel();
private JPanel p_20 = new JPanel();
private JPanel p_21 = new JPanel();
private ImageIcon icon1 = new ImageIcon("images" + File.separator+"01.jpg");
private ImageIcon icon2 = new ImageIcon("images" + File.separator+"02.jpg");
private ImageIcon icon3 = new ImageIcon("images" + File.separator+"03.jpg");
private ImageIcon icon4 = new ImageIcon("images" + File.separator+"04.jpg");
private ImageIcon icon5 = new ImageIcon("images" + File.separator+"05.jpg");
private ImageIcon icon6 = new ImageIcon("images" + File.separator+"06.jpg");
private ImageIcon icon7 = new ImageIcon("images" + File.separator+"07.jpg");
private ImageIcon icon8 = new ImageIcon("images" + File.separator+"08.jpg");
private ImageIcon icon9 = new ImageIcon("images" + File.separator+"09.jpg");
private ImageIcon icon10 = new ImageIcon("images" + File.separator+"10.jpg");
private ImageIcon icon11 = new ImageIcon("images" + File.separator+"11.jpg");
private ImageIcon icon12 = new ImageIcon("images" + File.separator+"12.jpg");
private ImageIcon icon13 = new ImageIcon("images" + File.separator+"13.jpg");
private ImageIcon icon14 = new ImageIcon("images" + File.separator+"14.jpg");
private ImageIcon icon15 = new ImageIcon("images" + File.separator+"15.jpg");
private ImageIcon icon16 = new ImageIcon("images" + File.separator+"16.jpg");
private ImageIcon icon17 = new ImageIcon("images" + File.separator+"17.jpg");
private ImageIcon icon18 = new ImageIcon("images" + File.separator+"18.jpg");
private ImageIcon icon19 = new ImageIcon("images" + File.separator+"19.jpg");
private ImageIcon icon20 = new ImageIcon("images" + File.separator+"20.jpg");
private ImageIcon icon21 = new ImageIcon("images" + File.separator+"21.jpg");
public TestMain2() {
super("大学美女展");
try {
// 将LookAndFeel设置成Windows样式
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
} catch (Exception ex) {
ex.printStackTrace();
}
/**创建一个具有指定的水平和垂直间隙的新卡片布局*/
card = new CardLayout();
pane = new JPanel(card); // JPanel的布局管理将被设置成CardLayout
p_1.add(new JLabel(icon1,JLabel.CENTER));
p_2.add(new JLabel(icon2,JLabel.CENTER));
p_3.add(new JLabel(icon3,JLabel.CENTER));
p_4.add(new JLabel(icon4,JLabel.CENTER));
p_5.add(new JLabel(icon5,JLabel.CENTER));
p_6.add(new JLabel(icon6,JLabel.CENTER));
p_7.add(new JLabel(icon7,JLabel.CENTER));
p_8.add(new JLabel(icon8,JLabel.CENTER));
p_9.add(new JLabel(icon9,JLabel.CENTER));
p_10.add(new JLabel(icon10,JLabel.CENTER));
p_11.add(new JLabel(icon11,JLabel.CENTER));
p_12.add(new JLabel(icon12,JLabel.CENTER));
p_13.add(new JLabel(icon13,JLabel.CENTER));
p_14.add(new JLabel(icon14,JLabel.CENTER));
p_15.add(new JLabel(icon15,JLabel.CENTER));
p_16.add(new JLabel(icon16,JLabel.CENTER));
p_17.add(new JLabel(icon17,JLabel.CENTER));
p_18.add(new JLabel(icon18,JLabel.CENTER));
p_19.add(new JLabel(icon19,JLabel.CENTER));
p_20.add(new JLabel(icon20,JLabel.CENTER));
p_21.add(new JLabel(icon21,JLabel.CENTER));
pane.add(p_1, "p1");
pane.add(p_2, "p2");
pane.add(p_3, "p3");
pane.add(p_4,"p4");
pane.add(p_5,"p5");
pane.add(p_6,"p6");
pane.add(p_7,"p7");
pane.add(p_8,"p8");
pane.add(p_9,"p9");
pane.add(p_10,"p10");
pane.add(p_11,"p11");
pane.add(p_12,"p12");
pane.add(p_13,"p13");
pane.add(p_14,"p14");
pane.add(p_15,"p15");
pane.add(p_16,"p16");
pane.add(p_17,"p17");
pane.add(p_18,"p18");
pane.add(p_19,"p19");
pane.add(p_20,"p20");
pane.add(p_21,"p21");
this.addMouseListener(new MouseAdapter(){ // 下一步的按钮动作
public void mouseClicked(MouseEvent e) {
card.next(pane);
}
});
this.getContentPane().add(pane);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(480, 400);
this.setResizable(false);
this.setVisible(true);
}
public static void main(String[] args) {
new TestMain2();
}
}