卡片佈局CardLaypoutTest

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);

}

}

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章