-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathChBox2.java
59 lines (48 loc) · 1.32 KB
/
ChBox2.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// State change using Checkbox - 2
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/* <applet code = "ChBox2" height = 300 width = 300> </applet> */
public class ChBox2 extends Applet implements ItemListener
{
Label l1.l2;
TextField t1,t2;
Checkbox cb1,cb2,cb3;
CheckboxGroup cbg;
public void init()
{
cbg = new CheckboxGroup();
cb1 = new Checkbox("Square",cbg,false);
cb2 = new Checkbox("Cube",cbg,false);
cb3 = new Checkbox("Quad",cbg,false);
t1 = new TextField(10);
t2 = new TextField(10);
l1 = new Label("Number");
l2 = new Label("Result");
add(l1); add(t1);
add(l2); add(t2);
add(cb1); add(cb2); add(cb3);
cb1.addItemListener(this);
cb2.addItemListener(this);
cb3.addItemListener(this);
}
public void itemState(ItemEvent e)
{
int n = Integer.parseInt(t1.getText());
int res = 0;
Checkbox c = cbg.getSelectedCheckbox();
if(c == cb1)
{
res = n * n;
}
else if(c == cb2)
{
res = n * n * n;
}
else if(c == cb3)
{
res = n * n * n * n;
}
t2.setText(" ", + res);
}
}