Repository navigation
Expand file tree
/
Copy pathCalculator1.java
More file actions
110 lines (85 loc) · 2.37 KB
/
Copy pathCalculator1.java
File metadata and controls
110 lines (85 loc) · 2.37 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import java.awt.*;
import java.awt.event.*;
// import java.awt.event.*;
public class Calculator1 extends Frame implements ActionListener {
Label L1,L2,L3,L4;
TextField T1,T2,T3;
Button B1,B2,B3,B4;
Calculator1(String title)
{
super(title);
setLayout(null);
setBackground(Color.pink);
setForeground(Color.BLUE);
L1=new Label("Calculator");
L2=new Label("Enter 1st number:",Label.RIGHT);
L3=new Label("Enter 2nd number:",Label.RIGHT);
L4=new Label("Result:",Label.RIGHT);
T1=new TextField(3);
T2=new TextField(3);
T3=new TextField(3);
B1=new Button("add");
B2=new Button("sub");
B3=new Button("mul");
B4=new Button("div");
L1.setBounds(200, 100, 200, 50);
L2.setBounds(200, 150, 200, 50);
L3.setBounds(200, 200, 200, 50);
L4.setBounds(200, 250, 200, 50);
T1.setBounds(450, 150, 200, 50);
T2.setBounds(450, 200, 200, 50);
T3.setBounds(450,250, 200, 50);
B1.setBounds(200, 350, 40, 50);
B2.setBounds(250, 350, 40, 50);
B3.setBounds(300, 350, 40, 50);
B4.setBounds(350, 350, 40, 50);
B1.addActionListener(this);
B2.addActionListener(this);
B3.addActionListener(this);
B4.addActionListener(this);
add(L1);
add(L2);
add(T1);
add(L3);
add(T2);
add(L4);
add(T3);
add(B1);
add(B2);
add(B3);
add(B4);
}
public void actionPerformed(ActionEvent ae)
{
int a=Integer.parseInt(T1.getText());
int b=Integer.parseInt(T2.getText());
int c;
if(B1==ae.getSource())
{
c=a+b;
T3.setText(c +"");//T3.setText(String.valueOf(c));;
}
else if(B2==ae.getSource())
{
c=a-b;
T3.setText(c+"");
}
else if(B3==ae.getSource())
{
c=a*b;
T3.setText(c+"");
}
else if(B4==ae.getSource())
{
c=a/b;
T3.setText(c+"");
}
}
public static void main(String[] args)
{
Calculator1 C=new Calculator1("calc");
C.setVisible(true);
C.setSize(700,500);
// C.setTitle("calc");
}
}