java GUI編程(swing)之三swing單選框複選框組件

來源:互聯網
上載者:User

標籤:pack   created   body   tla   ble   void   說明   標籤   layout   

swing複選框(JCheckBox) 單選框(JRadioButton) 特別說明:同一組選項按鈕,必須先建立一個ButtonGroup,然後把選項按鈕放到ButtonGroup中 package gui;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.JLabel;import javax.swing.JCheckBox;import javax.swing.JRadioButton;import javax.swing.ButtonGroup;import java.awt.GridLayout;/*** 單選框,複選框* Created by admin on 2017/7/6.*/public class MySelect extends JFrame{// 在此定義好需要用的組件private JButton jButton, jButton2;private JPanel jPanel, jPanel2, jPanel3;private JLabel jLabel, jLabel2;private JCheckBox jCheckBox1, jCheckBox2, jCheckBox3;private ButtonGroup buttonGroup;private JRadioButton jRadioButton, jRadioButton2,jRadioButton3, jRadioButton4;public static void main(String[] args){MySelect mySelect = new MySelect();}// 構造方法public MySelect(){// 面板jPanel = new JPanel();jPanel2 = new JPanel();jPanel3 =new JPanel();// 按鈕jButton = new JButton("確定");jButton2 = new JButton("取消");// 標籤jLabel = new JLabel("請選擇");jLabel2 = new JLabel("環境");// 複選jCheckBox1 = new JCheckBox("Python");jCheckBox2 = new JCheckBox("Java");jCheckBox3 = new JCheckBox("Python");// 單選jRadioButton = new JRadioButton("Linux");jRadioButton2 = new JRadioButton("Unix");jRadioButton3 = new JRadioButton("Windows");jRadioButton4 = new JRadioButton("Mac OS");// 單選框GroupbuttonGroup = new ButtonGroup();buttonGroup.add(jRadioButton);buttonGroup.add(jRadioButton2);buttonGroup.add(jRadioButton3);buttonGroup.add(jRadioButton4); jPanel.add(jLabel);jLabel.add(jCheckBox1);jPanel.add(jCheckBox2);jPanel.add(jCheckBox3);jPanel2.add(jLabel2);jPanel2.add(jRadioButton);jPanel2.add(jRadioButton2);jPanel2.add(jRadioButton3);jPanel2.add(jRadioButton4); jPanel3.add(jButton);jPanel3.add(jButton2); this.setLayout(new GridLayout(3, 1));this.add(jPanel);this.add(jPanel2);this.add(jPanel3);//設定JFrame屬性this.setTitle("工程");this.setLocation(500, 250);this.setSize(350, 200);this.setResizable(false);this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);this.setVisible(true);}} 

java GUI編程(swing)之三swing單選框複選框組件

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.