📄 checkbox.java
字号:
//<applet code = "checkbox.class" height = 300 width = 200></applet>
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
class P1 extends Panel
{
ScrollPane scrollpane;
P1()
{
TextField word = new TextField("全班30人买下列东西,一共需要多少钱",20);
scrollpane=new ScrollPane(1);
scrollpane.add(word);
add(scrollpane);
}
}
class P2 extends Panel
{
Checkbox box1,box2,box3,box4;
P2()
{
setLayout(new GridLayout(2,2));
box1 = new Checkbox("5/本");
box2 = new Checkbox("2/只");
box3 = new Checkbox("16/本");
box4 = new Checkbox("38/本");
add(box1);
add(box2);
add(box3);
add(box4);
}
}
class P3 extends Panel
{
Label label;
TextField text;
Button button;
P3()
{
label = new Label("总金额");
text = new TextField(10);
button = new Button("确定");
button.setBackground(Color.green);
add(label);
add(text);
add(button);
}
}
public class checkbox extends Applet implements ItemListener,ActionListener
{
P1 p1;
P2 p2;
P3 p3;
int a1=0,a2=0,a3=0,a4=0;
int sum = 0;
public void init()
{
p1 = new P1();
p2 = new P2();
p3 = new P3();
add(p1);
add(p2);
add(p3);
p2.box1.addItemListener(this);
p2.box2.addItemListener(this);
p2.box3.addItemListener(this);
p2.box4.addItemListener(this);
p3.button.addActionListener(this);
}
public void itemStateChanged(ItemEvent e)
{
if(e.getItemSelectable()==p2.box1)
{
a1 = 5;
}
if(e.getItemSelectable()==p2.box2)
{
a2 = 2;
}
if(e.getItemSelectable()==p2.box3)
{
a3 = 16;
}
if(e.getItemSelectable()==p2.box4)
{
a4 = 38;
}
sum = a1+a2+a3+a4;
sum *= 30;
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == p3.button)
{
p3.text.setText(String.valueOf(sum));
p2.box1.setState(false);
p2.box2.setState(false);
p2.box3.setState(false);
p2.box4.setState(false);
a1=a2=a3=a4=0;
sum = 0;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -