-
Notifications
You must be signed in to change notification settings - Fork 3
/
CBCalc.java
53 lines (43 loc) · 1.25 KB
/
CBCalc.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
// Input a number, output a result. 3 checkboxes, square,cube,quad. Return the relevant result
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/*<applet code = "CBCalc" width = 100 height = 100> </applet> */
public class CBCalc extends Applet implements ActionListener
{
Checkbox cb1,cb2,cb3;
Label l1,l2;
TextFields t1,t2;
public void init()
{
cb1 = new Checkbox("Power of 2 (SQUARE) : ");
cb2 = new Checkbox("Power of 3 (CUBE) : ");
cb3 = new Checkbox("Power of 4 (QUAD) : ");
l1 = new Label("Number : ");
l2 = new Label("Result : ");
add(l1); add(t1);
add(l2); add(t2);
add(cb1); add(cb2); add(cb3);
cb1.addActionListener(this);
cb2.addActionListener(this);
cb3.addActionListener(this);
}
public void itemStateChanged(ItemEvent e)
{
int n = Integer.parseInt(t1.getText());
int res = 0;
if(cb1.getState())
{
res = n * n;
}
else if(cb2.getState())
{
res = n * n * n;
}
else if(cb3.getState())
{
res = n * n * n * n;
}
t2.setText(" " + res);
}
}