布局管理器—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)  編輯  收藏 所屬分類: 學習筆記

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

          導航

          統計

          公告

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

          常用鏈接

          留言簿(1)

          隨筆檔案

          文章分類

          文章檔案

          學習園地

          最新隨筆

          搜索

          積分與排名

          最新評論

          主站蜘蛛池模板: 旺苍县| 浠水县| 永胜县| 抚宁县| 绵竹市| 体育| 商水县| 玛多县| 辉南县| 泰安市| 江达县| 武定县| 贵州省| 胶州市| 瑞金市| 汤阴县| 如皋市| 甘南县| 宜城市| 蚌埠市| 东阳市| 涿鹿县| 合水县| 阳新县| 保德县| 福泉市| 胶南市| 永仁县| 伊川县| 托里县| 龙海市| 柞水县| 桐城市| 峨眉山市| 福鼎市| 通江县| 永宁县| 南开区| 丰镇市| 祁门县| 桐庐县|