java [24] 图形化 复选框和单选框组件

package graph;

/*
 * 
 * 
 * 
 * 复选框和单选框组件
*/

import java.awt.*;
import javax.swing.*;

public class demo7 extends JFrame{
	JPanel jp1,jp2,jp3;
	JLabel jlb1,jlb2;
	JButton jb1,jb2;
	JCheckBox jcb1,jcb2,jcb3;
	JRadioButton jrb1,jrb2;
	ButtonGroup bg;
	
	
	
	public static void main(String[] args) {
		demo7 demo = new demo7();
		
	}
	
	
	
	
	public demo7() {
		//创建组件
		jp1 = new JPanel();
		jp2 = new JPanel();
		jp3 = new JPanel();
		
		jlb1 = new JLabel("你喜欢的运动:");
		jlb2 = new JLabel("你的性别:");
		jb1 = new JButton("注册用户");
		jb2 = new JButton("取消用户");
		
		jcb1 = new JCheckBox("篮球");
		jcb2 = new JCheckBox("足球");
		jcb3 = new JCheckBox("羽毛球");
		
		jrb1 = new JRadioButton("男");
		jrb2 = new JRadioButton("女");
		bg = new ButtonGroup();
		bg.add(jrb1);
		bg.add(jrb2);
		
		//设置布局管理
		this.setLayout(new GridLayout(3, 1));
		
		//添加组件
		jp1.add(jlb1);
		jp1.add(jcb1);
		jp1.add(jcb2);
		jp1.add(jcb3);
		
		jp2.add(jlb2);
		jp2.add(jrb1);
		jp2.add(jrb2);
		
		jp3.add(jb1);
		jp3.add(jb2);
		
		this.setTitle("用户注册界面");
		this.add(jp1);
		this.add(jp2);
		this.add(jp3);
		this.setSize(300, 150);
		this.setLocation(300, 300);
		this.setDefaultCloseOperation(this.EXIT_ON_CLOSE);
		this.setVisible(true);
	}
}

猜你喜欢

转载自blog.csdn.net/qq_38125626/article/details/81286045