复选框——Checkbox的实例使用
程序员文章站
2022-05-31 13:30:08
...
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class Ex_Checkbox extends Frame{
Checkbox c1,c2,c3,c4;
Panel p,panel;
Label label;
public Ex_Checkbox(String title) {
super(title);
c1= new Checkbox("C语言",false);//"C语言" 是标签内容,false指定状态 (不打勾)
c2= new Checkbox("java",false);
c3= new Checkbox("Nosql",true); //true 默认 √
c4= new Checkbox("python");
label = new Label("你喜欢哪种语言?");
p = new Panel();
panel = new Panel();
p.add(label);
panel.add(c1);
panel.add(c2);
panel.add(c3);
panel.add(c4);
add(p);
p.add(panel);
setSize(300,180);
setVisible(true);
addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {System.exit(0);}});
}
public static void main(String arg[]) {
new Ex_Checkbox("复选框");
}
}