java筆記之圖形類----非組件容器詳解

來源:互聯網
上載者:User

標籤:rgs   輸入框   java筆記   上海   code   sla   roi   microsoft   word   

Java的非容器組件:

加入非容器步驟:

1.建立一個Jframe

2.建立面板Jpanel

3.將面板加入到Jframe中

4.添加Jlabel標籤

5.新群組件

a:JTextField  文本輸入框  可指定輸入框大小

b:JPasswordField 文本密文輸入

JPasswordField passwordField=new JPasswordField(10);

c:JRadioButton 選項按鈕

JRadioButton man = new JRadioButton("男",true);
JRadioButton woman = new JRadioButton("女");
//如果是單選框必須要進行分組,同一個組的單選框只能選擇其中的一個
ButtonGroup group = new ButtonGroup();
group.add(woman);
group.add(man);

d:JComboBox下拉框

Object[] arr = {"北京","上海","廣州","深圳","湛江"};
JComboBox citys = new JComboBox(arr);

e:JCheckBox多選框

JCheckBox checkBox1 = new JCheckBox("籃球",true);

f:JTextArea大文本輸入框

JTextArea area = new JTextArea(20, 15);
area.setLineWrap(true); //設定自動換行

6.將其加入面板中

7.初始化frame

import javax.swing.ButtonGroup;import javax.swing.JCheckBox;import javax.swing.JComboBox;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JPasswordField;import javax.swing.JRadioButton;import javax.swing.JTextArea;import javax.swing.JTextField;import cn.itcast.util.FrameUtil;/* 非容器組件: */public class Demo1 {        public static void main(String[] args) {        JFrame frame= new JFrame("註冊");        //建立一個面板        JPanel panel = new JPanel();        frame.add(panel);         //使用者名稱        JLabel nameLabel = new JLabel("使用者名稱"); //使用者名稱的輸入框 JTextField nameField = new JTextField(12); //把使用者名稱的組件添加到面板上 panel.add(nameLabel); panel.add(nameField); //密碼 JLabel passLabel= new JLabel("密碼"); //密碼框 JPasswordField passField = new JPasswordField(12); //把密碼的組件添加到面板 panel.add(passLabel); panel.add(passField); //性別--單選框 JLabel sexLabel = new JLabel("性別"); JRadioButton man = new JRadioButton("男",true); JRadioButton woman = new JRadioButton("女"); //如果是單選框必須要進行分組,同一個組的單選框只能選擇其中的一個 ButtonGroup group = new ButtonGroup(); group.add(woman); group.add(man); //把性別組件添加到面板上 panel.add(sexLabel); panel.add(man); panel.add(woman); //來自城市--->下拉框 JLabel cityLabel = new JLabel("來自的城市"); Object[] arr = {"北京","上海","廣州","深圳","湛江"}; JComboBox citys = new JComboBox(arr); panel.add(cityLabel); panel.add(citys); //興趣愛好---->複選框 JLabel hobitLabel = new JLabel("興趣愛好:"); JCheckBox checkBox1 = new JCheckBox("籃球",true); JCheckBox checkBox2 = new JCheckBox("java",true); JCheckBox checkBox3 = new JCheckBox("javascript"); JCheckBox checkBox4 = new JCheckBox("android"); panel.add(hobitLabel); panel.add(checkBox1); panel.add(checkBox2); panel.add(checkBox3); panel.add(checkBox4); //簡歷 JLabel jLabel = new JLabel("簡歷"); JTextArea area = new JTextArea(20, 15); area.setLineWrap(true); //設定自動換行  panel.add(jLabel); panel.add(area); FrameUtil.initFrame(frame, 500, 400); } 

 :

 

java筆記之圖形類----非組件容器詳解

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.