BoxLayout組件

          /**
          ?* @(#)TestBoxLayout.java
          ?*
          ?* TestBoxLayout application
          ?*
          ?* @author
          ?* @version 1.00 2007/1/25
          ?*/
          import javax.swing.*;
          import java.awt.*;
          import java.awt.event.*;
          import java.util.EventListener;
          public class TestBoxLayout extends JFrame implements ActionListener
          {
          ?JTextField jtf=new JTextField();?
          ??? public TestBoxLayout()
          ??? {
          ??? ?this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          ??? ?Container c=this.getContentPane();
          ??? ?
          ??? ?JPanel jpl1=new JPanel();
          ??? ?JPanel jpl2=new JPanel();
          ??? ?JPanel jpl3=new JPanel();
          ??? ?JPanel jpl4=new JPanel();
          ??? ?
          ??? ?//BoxLayout blo=new BoxLayout(jtf,BoxLayout.LINE_AXIS);
          ??? ?BoxLayout blo1=new BoxLayout(jpl1,BoxLayout.X_AXIS);
          ??? ?BoxLayout blo2=new BoxLayout(jpl2,BoxLayout.X_AXIS);
          ??? ?BoxLayout blo3=new BoxLayout(jpl3,BoxLayout.X_AXIS);
          ??? ?BoxLayout blo4=new BoxLayout(jpl4,BoxLayout.X_AXIS);
          ??? ?/*
          ??? ?blo1.maximumLayoutSize(jpl1);
          ??? ?blo2.maximumLayoutSize(jpl2);
          ??? ?blo3.maximumLayoutSize(jpl3);
          ??? ?blo4.maximumLayoutSize(jpl4);
          ??? ?*/
          ??? ?jpl1.setLayout(blo1);
          ??? ?jpl2.setLayout(blo2);
          ??? ?jpl3.setLayout(blo3);
          ??? ?jpl4.setLayout(blo4);
          ??? ?
          ??? ?JButton jb=null;
          ???
          ??? ?for(int i=0;i<4;i++)
          ??? ?{
          ??? ??String str=new String("123+");
          ??? ??Character ch=str.charAt(i);
          ??? ??jb=new JButton(ch.toString());
          ??? ??jb.setSize(100,100);
          ??? ??jpl1.add(jb);
          ??? ??jb.addActionListener(this);
          ??? ?}
          ??? ?for(int i=0;i<4;i++)
          ??? ?{
          ??? ??String str=new String("456-");
          ??? ??Character ch=str.charAt(i);
          ??? ??jb=new JButton(ch.toString());
          ??? ??jpl2.add(jb);
          ??? ??jb.addActionListener(this);
          ??? ?}
          ?? ???
          ??? ?for(int i=0;i<4;i++)
          ??? ?{
          ??? ??String str=new String("789*");
          ??? ??Character ch=str.charAt(i);
          ??? ??jb=new JButton(ch.toString());
          ??? ??jpl3.add(jb);
          ??? ??jb.addActionListener(this);
          ??? ?}
          ??? ?for(int i=0;i<4;i++)
          ??? ?{
          ??? ??String str=new String("0.=\\");
          ??? ??Character ch=str.charAt(i);
          ??? ??jb=new JButton(ch.toString());
          ??? ??jpl4.add(jb);
          ??? ??jb.addActionListener(this);
          ??? ?}
          ??? ?c.setLayout(new GridLayout(5,1));
          ??? ?c.add(jtf);
          ??? ?c.add(jpl1);
          ??? ?c.add(jpl2);
          ??? ?c.add(jpl3);
          ??? ?c.add(jpl4);
          ??? }
          ??? public static void main(String[] args)
          ??? {
          ??? ?
          ??? ?// TODO, add your application code
          ??? ?System.out.println("Hello World!");
          ??? ?TestBoxLayout mainFrame=new TestBoxLayout();
          ??? ?mainFrame.setTitle("TestBoxLayout");
          ??? ?mainFrame.setBounds(300,200,200,200);
          ??? ?mainFrame.setVisible(true);
          ??? }

          ?/**
          ? * Method actionPerformed
          ? *
          ? *
          ? * @param e
          ? *
          ? */
          ?public void actionPerformed(ActionEvent e)
          ?{
          ??// TODO: Add your code here
          ??jtf.setText(jtf.getText()+e.getActionCommand());
          ??//d.setText(jfd.getText()+e.getActionCommand());
          ?}
          }

          posted on 2007-01-26 15:16 大頭劍客 閱讀(849) 評論(0)  編輯  收藏 所屬分類: 學習筆記

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

          導航

          統計

          公告

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

          常用鏈接

          留言簿(1)

          隨筆檔案

          文章分類

          文章檔案

          學習園地

          最新隨筆

          搜索

          積分與排名

          最新評論

          主站蜘蛛池模板: 石城县| 晋中市| 青浦区| 兰考县| 色达县| 察雅县| 西华县| 东乌珠穆沁旗| 保靖县| 永吉县| 沅江市| 湘乡市| 延庆县| 红桥区| 诸暨市| 汝州市| 罗山县| 虎林市| 永福县| 万州区| 邵阳县| 青州市| 赤峰市| 临西县| 剑河县| 高要市| 奉化市| 玛多县| 兖州市| 西丰县| 房产| 乐山市| 鲁山县| 得荣县| 寿阳县| 明溪县| 资阳市| 镇原县| 巴林左旗| 安远县| 绥宁县|