在图形用户界面编程中,我们常常会提供用户注册界面,这时候我们就会用到:
1、复选框组件 (JCheckBox)
2、单选框组件 (JRadioBuutton)
特别说明:
同一组单选按钮必需先创建 ButtonGroup ,然后把单选框组件放入到 ButtonGroup 中
下面举例说明:
/**
* 测试:JCheckBox/JRadioButton
*/
package com.test1;
import java.awt.*;
import javax.swing.*;
public class Demo8_7 extends JFrame{
//定义小控件
JPanel jp1 = null;
JPanel jp2 = null;
JPanel jp3 = null;
JLabel jlb1 = null;
JLabel jlb2 = null;
JButton jb1 = null;
JButton jb2 = null;
JCheckBox jcb1 = null;
JCheckBox jcb2 = null;
JCheckBox jcb3 = null;
JRadioButton jrb1 = null;
JRadioButton jrb2 = null;
ButtonGroup bg = null;
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Demo8_7 demo8_7 = new Demo8_7(300, 200);
}
public Demo8_7(int x_dispS