多选按钮实例
package ss;
import java.awt.*;
public class Frame2 {
static Frame f=new Frame("QQ");
static Label l1=new Label("爱好:");
static Label l2=new Label("性别:");
static Checkbox like1=new Checkbox("读书",true);
static Checkbox like2=new Checkbox("上网",true);
static Checkbox like3=new Checkbox("打游戏");
static CheckboxGroup sex=new CheckboxGroup();
static Checkbox man=new Checkbox("男");
static Checkbox woman=new Checkbox("女");
public static void main(String[] args) {
// TODO Auto-generated method stub
f.setVisible(true);
f.setBounds(100, 100, 500, 400);
f.setBackground(new Color(220,220,220));
f.setLayout(null);
f.setResizable(false);
man.setCheckboxGroup(sex);
woman.setCheckboxGroup(sex);
sex.setSelectedCheckbox(man);
l1.setBounds(60, 60, 60, 20);
like1.setBounds(60,90,60,20);
like2.setBounds(130,90,60,20);
like3.setBounds(200,90,60,20);
l2.setBounds(60, 160, 60, 20);
man.setBounds(60,190,60,20);
woman.setBounds(130,190,60,20);
f.add(l1);
f.add(l2);
f.add(like1);
f.add(like2);
f.add(like3);
f.add(man);
f.add(woman);
}
}