Swing常用控件使用笔记

 1netbeans是开发java左面应用程序的一个好的帮手,为了给自己备个案,现在决定把swing的常用的控件记录下来。以备以后使用。

 

  1文本标签控件  Jlable  jlableUserName=new JLabel("用户名:");

  2文本框控件   JtextField username=new JTextField();

  3密码控件         JPasswordField password=new JPasswordField();

      4按钮控件    JButton jbuttonEntry=new JButton();

      5文本区域     JTextArea myTextArea=new JTextArea(int rows,int columns);本身不滚动,要想滚动,需要加如到JScrollPane里面,

     如:JScrollPane myScrollPane=new JscrollPane(mytextArea);

    另外:this.myTextArea.setlineWrap(true/false);设置是否换行。

  6JCheckBox

        A有两个状态:选中,非选中

   B一定要在一个组里面才有效。

   CJCheckBox box=new JCheckBox("文本框"); JCheckBox box=new JCheckBox("check.jpg"); 

          JCheckBox box=new JCheckBox("image",selected)图标和是否选中

  7JRadioButton

        A一定要在组里面

   BButtonGroup bu=new ButtonGroup();

          JRadioButton one=new JRadioButton("one");

          JRadioButton two=new JRadioButton("two");

          bu.add(one);

          bu.add(two);

  8JComboBox

         1JComboBox  box=new JComboBox();

         2构造函数

     JComboBox()

             JComboBox(Object[] items)

             JComboBox(Vector vector)

             JComboBox(ComboBoxModel model)

         3常用方法

         setEditable(boolean flag)

            setMaximumRow(int rows)

            setMaximumRowCount();不滚动时可以看到的最大行数

      getSelectdItem,

            addItem(Object object)

2设置控件的位置:

       this.setbounds(330,250,300,150);

                  this.setVisible(true);

 

3启动一个窗体

       public static void main(String args[]) {
                  java.awt.EventQueue.invokeLater(new Runnable() {
                  public void run() {
                     new BrookJFrame().setVisible(true);
                  }
                 });
                }

4主要事件

     A动作事件:ActionListener接口

     B键盘事件:KeyListener接口

     C鼠标事件:MouseListener,MouseMotionListerer,MousewheelListerer 3个接口

     D窗口事件:WindowFocusListener,WindowListerer,WindowStateListerer.

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值