日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

swing之单选框和复选框

發布時間:2025/4/16 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 swing之单选框和复选框 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1 import java.awt.Container; 2 import java.awt.GridLayout; 3 4 import javax.swing.*; 5 6 7 public class num_1v extends JFrame{ 8 //聲明控件和布局管理器 9 JRadioButton[] rb = new JRadioButton[5]; 10 JCheckBox check[] = new JCheckBox[5]; 11 JComboBox<String> jcb; 12 JTextArea jta; 13 JButton jb; 14 //構造方法 15 public num_1v(){ 16 Container con = getContentPane();// 創建容器,默認邊界布局 17 GridLayout gr = new GridLayout(2,1);// 聲明5行1列的網格布局 18 con.setLayout(gr); 19 // 第一行 20 JPanel jp1 = new JPanel();// 創建面板 21 jp1.setLayout(new GridLayout(3,1)); 22 //第一行 -- 第一子行 23 JPanel jp1_1 = new JPanel(); 24 JLabel lb1 = new JLabel("年齡段");// 創建標簽 25 jp1_1.add(lb1); 26 ButtonGroup bg = new ButtonGroup(); // 創建單選按鈕組 27 String[] rbstr = {"5-15歲","16-25歲","26-35歲","36-45歲","46-55歲"}; 28 for (int i = 0;i<rbstr.length;i++){ 29 rb[i] = new JRadioButton(rbstr[i]);// 定義按鈕組對象 30 bg.add(rb[i]); 31 jp1_1.add(rb[i]); 32 } 33 jp1.add(jp1_1); 34 //第一行 -- 第二子行 35 JPanel jp1_2 = new JPanel();// 新建面板2放置復選框 36 JLabel lb2 = new JLabel("興趣愛好"); 37 jp1_2.add(lb2); 38 String[] cbstr = {"交友","戶外","購物","閱讀","其它"};// 定義字符串數組,存放單選按鈕名稱 39 for (int i = 0;i < rb.length;i++){ 40 check[i] = new JCheckBox(cbstr[i]); 41 jp1_2.add(check[i]); 42 } 43 jp1.add(jp1_2); 44 //第一行 -- 第三子行 45 JPanel jp1_3 = new JPanel();// 新建面板pan3放置下拉列表 46 JLabel lb3 = new JLabel("院系");// 新建標簽 47 jp1_3.add(lb3); 48 String[] deNames = {"電子信息學院","商學院","人文藝術學院",}; 49 jcb = new JComboBox<String>(deNames); 50 jp1_3.add(jcb);// 把控件添加到面板3 51 jb = new JButton("提交"); 52 jp1_3.add(jb); 53 jp1.add(jp1_3); // 把面板添加到容器 54 con.add(jp1); 55 //第二行 56 jta = new JTextArea(3,3); 57 jta.setLineWrap(true); 58 JScrollPane jsp = new JScrollPane(jta); 59 con.add(jsp); 60 setSize(500, 350);// 設置窗體大小 61 setTitle("單選框復選框測試"); // 設置窗體標題 62 // setResizable(false); //窗體不可以調整大小 63 setLocationRelativeTo(null);// 設置窗體在中央 64 setDefaultCloseOperation(EXIT_ON_CLOSE); 65 setVisible(true);// 設置窗體可見 66 } 67 public static void main(String[] args) { 68 new num_1v(); 69 } 70 }

?

轉載于:https://www.cnblogs.com/WuYangdan-5201314/p/10910200.html

總結

以上是生活随笔為你收集整理的swing之单选框和复选框的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。