/*
* 多选框的使用
*/
package com.swing;
import java.awt.GridLayout;
import javax.swing.*;
class jcheckbox extends JFrame{
public static void main(String[] args){
jcheckbox jbox = new jcheckbox();
}
JCheckBox jcbox1,jcbox2,jcbox3;
JLabel jlb1,jlb2;
JRadioButton jrbtn1,jfbtn2;
JPanel jp1,jp2,jp3;
JButton jb1,jb2;
public jcheckbox(){
jcbox1=new JCheckBox("篮球");
jcbox2=new JCheckBox("乒乓球");
jcbox3=new JCheckBox("足球");
jlb1=new JLabel("你喜欢的运动");
jlb2=new JLabel("你的性别");
jb1=new JButton("注册");
jb2=new JButton("取消");
JRadioButton jrbtn1=new JRadioButton("男");
JRadioButton jrbtn2=new JRadioButton("女");
ButtonGroup bgroup=new ButtonGroup();
//设置为流式布局
this.setLayout(new GridLayout(3,1));
jp1=new JPanel();
jp1.add(jlb1);
jp1.add(jcbox1);
jp1.add(jcbox2);
jp1.add(jcbox3);
this.add(jp1);
//第二行
jp2=new JPanel();
jp2.add(jlb2);
bgroup.add(jrbtn1);
bgroup.add(jrbtn2);
jp2.add(jrbtn1);
jp2.add(jrbtn2);
this.add(jp2);
//第三行
jp3=new JPanel();
jp3.add(jb1);
jp3.add(jb2);
this.add(jp3);
this.setTitle("多选框的使用");
this.setSize(300,150);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
}
转载于:https://blog.51cto.com/6846041/1329818