📄 checkbox1.java
字号:
import java.awt.*;
import java.awt.event.*;
class Mypanel1 extends Panel implements ItemListener {
Checkbox box1, box2, box3;
CheckboxGroup sex;
TextArea text;
Mypanel1(TextArea text) {
this .text = text;
sex =new CheckboxGroup();
box1 = new Checkbox("boy",true,sex);
box2 = new Checkbox("girl",false,sex);
box1.addItemListener(this);
box2.addItemListener(this);
add(box1);
add(box2);
}
public void itemStateChanged(ItemEvent e) {
Checkbox box = (Checkbox)e.getSource();
if(box.getState()){
int n = text.getCaretPosition();
text.insert(box.getLabel() + "\n",n);
}
}
}
class Mypanel2 extends Panel implements ItemListener {
Checkbox box1, box2, box3;
TextArea text;
Mypanel2(TextArea text) {
this .text = text;
box1 = new Checkbox("zhansan");
box2 = new Checkbox("li shi");
box1.addItemListener(this);
box2.addItemListener(this);
add(box1);
add(box2);
}
public void itemStateChanged(ItemEvent e) {
Checkbox box = (Checkbox)e.getItemSelectable();
if(box.getState()){
int n = text.getCaretPosition();
text.insert(box.getLabel() + "\n",n);
}
}
}
class WindowBox extends Frame{
Mypanel1 panel1;
Mypanel2 panel2;
TextArea text;
WindowBox() {
text = new TextArea();
panel1 = new Mypanel1(text);
panel2 = new Mypanel2(text);
add(panel1,BorderLayout.SOUTH);
add(panel2,BorderLayout.NORTH);
add(text,BorderLayout.CENTER);
setSize(200,200);
setVisible(true);
validate();
}
}
public class CheckBox1 {
public static void main(String arg[]) {
new WindowBox();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -