-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAwtCalculator.java
More file actions
92 lines (70 loc) · 1.91 KB
/
Copy pathAwtCalculator.java
File metadata and controls
92 lines (70 loc) · 1.91 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package projects;
import java.awt.*;
import java.awt.event.*;
public class AwtCalculator implements ActionListener{
Frame f = new Frame();
Button b1,b2,b3,b4,b5;
Label l1,l2,l3;
TextField t1,t2,t3;
AwtCalculator(){
l1 = new Label("Enter Number 1 : ");
l1.setBounds(100,100,100,30);
t1 = new TextField();
t1.setBounds(200,100,200,30);
l2 = new Label("Enter Number 2 : ");
l2.setBounds(100,200,100,30);
t2 = new TextField();
t2.setBounds(200,200,200,30);
l3 = new Label("Result : ");
l3.setBounds(100,300,100,30);
t3 = new TextField();
t3.setBounds(200,300,200,30);
b1 = new Button("Add");
b1.setBounds(100,400,60,30);
b1.addActionListener(this);
b2 = new Button("Sub");
b2.setBounds(170,400,60,30);
b2.addActionListener(this);
b3 = new Button("Mul");
b3.setBounds(240,400,60,30);
b3.addActionListener(this);
b4 = new Button("Div");
b4.setBounds(310,400,60,30);
b4.addActionListener(this);
b5 = new Button("Cancel");
b5.setBounds(380,400,60,30);
b5.addActionListener(this);
f.add(b1);f.add(b2);f.add(b3);f.add(b4);f.add(b5);
f.add(l1);f.add(l2);f.add(l3);
f.add(t1);f.add(t2);f.add(t3);
f.setLayout(null);
f.setVisible(true);
f.setSize(700,500);
f.setTitle("Calculator");
}
public static void main(String[] args) {
AwtCalculator c = new AwtCalculator();
}
@Override
public void actionPerformed(ActionEvent e) {
int num1 = Integer.parseInt(t1.getText());
int num2 = Integer.parseInt(t2.getText());
// String num1 = t1.getText();
// String num2 = t2.getText();
if(e.getSource()==b1) {
t3.setText(Integer.toString(num1+num2));
}
else if(e.getSource()==b2) {
t3.setText(Integer.toString(num1-num2));
}
else if(e.getSource()==b3) {
t3.setText(Integer.toString(num1*num2));
}
else if(e.getSource()==b4) {
t3.setText(Integer.toString(num1/num2));
}
else {
f.setVisible(false);
}
}
}