布局管理器—CardLayout、GridLayout(Panel組件)

          /**
          ?* @(#)TestCardLayout.java
          ?*
          ?* TestCardLayout application
          ?*
          ?* @author
          ?* @version 1.00 2007/1/21
          ?*/
          ?import java.awt.*;
          ?import java.awt.event.*;
          ?
          public class TestCardLayout extends Frame
          {?
          ?CardLayout cl=new CardLayout();
          ??? Panel plCenter=new Panel(cl);
          ??? public TestCardLayout()
          ??? {
          ??? ?GridLayout gl=new GridLayout(5,1);
          ??? ?Panel plWest=new Panel(gl);
          ??? ?Button first=new Button("first");
          ??? ?Button prev=new Button("prev");
          ??? ?Button next=new Button("next");
          ??? ?Button three=new Button("three");
          ??? ?Button last=new Button("last");
          ??? ?plWest.add(first);
          ??? ?plWest.add(prev);
          ??? ?plWest.add(next);
          ??? ?plWest.add(three);
          ??? ?plWest.add(last);
          ??
          ??? ?plCenter.add(new Button("one"),"1");
          ??? ?plCenter.add(new Button("two"),"2");
          ??? ?plCenter.add(new Button("three"),"3");
          ??? ?plCenter.add(new Button("four"),"4");
          ??? ?plCenter.add(new Button("five"),"5");
          ??? ?add(plWest,"West");
          ??? ?add(plCenter);
          ??? ?class MyactionListener implements ActionListener
          ??? ?{
          ??? ??public void actionPerformed(ActionEvent e)
          ??? ??{
          ??? ???if(e.getActionCommand().equals("first"))
          ??? ???{
          ??? ????cl.first(plCenter);
          ??? ???}
          ??? ???else if(e.getActionCommand().equals("prev"))
          ??? ???{
          ??? ????cl.previous(plCenter);
          ??? ???}
          ??? ???else if(e.getActionCommand().equals("next"))
          ??? ???{
          ??? ????cl.next(plCenter);
          ??? ???}
          ??? ???else if(e.getActionCommand().equals("three"))
          ??? ???{
          ??? ????cl.show(plCenter,"3");
          ??? ???}
          ??? ???else
          ??? ???{
          ??? ????cl.last(plCenter);
          ??? ???}
          ??? ??}
          ??? ?}
          ??? ?MyactionListener ml=new MyactionListener();
          ??? ?first.addActionListener(ml);
          ??? ?prev.addActionListener(ml);
          ??? ?next.addActionListener(ml);
          ??? ?three.addActionListener(ml);
          ??? ?last.addActionListener(ml);
          ??? ?addWindowListener(new WindowAdapter()
          ??? ?{
          ??? ??public void windowClosing(WindowEvent e)
          ??? ??{
          ??? ???e.getWindow().dispose();
          ??? ??}
          ??? ?});
          ??? }
          ??? public static void main(String[] args)
          ??? {
          ??? ?
          ??? ?// TODO, add your application code
          ??? ?System.out.println("Hello World!");
          ??? ?TestCardLayout mainFrame=new TestCardLayout();
          ??? ?mainFrame.setTitle("TestCardLayout");
          ??? ?mainFrame.setBounds(300,200,400,400);
          ??? ?mainFrame.setVisible(true);
          ??? ?
          ??? }
          }

          posted on 2007-01-21 13:01 大頭劍客 閱讀(615) 評論(0)  編輯  收藏 所屬分類: 學(xué)習(xí)筆記

          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          導(dǎo)航

          統(tǒng)計

          公告

          寫字樓里寫字間,寫字間里程序員;
          程序人員寫程序,又拿程序換酒錢;
          酒醒只在網(wǎng)上坐,酒醉還來網(wǎng)下眠;
          酒醉酒醒日復(fù)日,網(wǎng)上網(wǎng)下年復(fù)年;
          但愿老死電腦間,不愿鞠躬老板前;
          奔馳寶馬貴者趣,公交自行程序員;
          別人笑我忒瘋癲,我笑自己命太賤;
          不見滿街漂亮妹,哪個歸得程序員.
          不管前面是地雷陣還是萬丈深淵,
          我都將勇往直前,義無反顧,
          鞠躬盡瘁,死而后已。
          —— 朱镕基總理

          常用鏈接

          留言簿(1)

          隨筆檔案

          文章分類

          文章檔案

          學(xué)習(xí)園地

          最新隨筆

          搜索

          積分與排名

          最新評論

          主站蜘蛛池模板: 双桥区| 赣州市| 福清市| 定远县| 衡东县| 长汀县| 霍邱县| 石棉县| 清原| 治多县| 乌兰浩特市| 防城港市| 淳安县| 六安市| 呼伦贝尔市| 辽阳市| 丰顺县| 贺兰县| 北宁市| 襄垣县| 孟村| 龙山县| 金湖县| 秀山| 南川市| 武汉市| 达拉特旗| 西盟| 兴化市| 水富县| 时尚| 德安县| 乌恰县| 龙岩市| 来凤县| 宁明县| 昂仁县| 大化| 区。| 巨鹿县| 蛟河市|