/*复选框和单选框*/
package com.i;
import java.awt.*;
import javax.swing.*;
public class Calculator extends JFrame{ //继承JFrame类
JButton an1,an2; //添加组件及面板
JPanel mb1,mb2,mb3;
JLabel bq1,bq2;
JRadioButton dxk1,dxk2;
JCheckBox fxk1,fxk2,fxk3;
ButtonGroup dxz;
public static void main(String[] args){
Calculator a = new Calculator();
}
public Calculator(){
mb1 = new JPanel();
mb2 = new JPanel();
mb3 = new JPanel();
bq1 = new JLabel("特长");
bq2 = new JLabel("性别");
fxk1 = new JCheckBox("音乐");
fxk2 = new JCheckBox("体育");
fxk3 = new JCheckBox("文艺");
dxk1 = new JRadioButton("男");
dxk2 = new JRadioButton("女");
an1 = new JButton("注册");
an2 = new JButton("取 消");
this.setLayout(new GridLayout(3,1));
dxz = new ButtonGroup();
dxz.add(dxk1);
dxz.add(dxk2);
mb1.add(bq1);
mb1.add(fxk1);
mb1.add(fxk2);
mb1.add(fxk3);
mb2.add(bq2);
mb2.add(dxk1);
mb2.add(dxk2);
mb3.add(an1);
mb3.add(an2);
this.add(mb1);
this.add(mb2);
this.add(mb3);
this.setTitle("用户注册");
this.setSize(240,150);
this.setLocation(300,200);
this.setResizable(false);//false时表示不可变大变小
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
}
效果图: