-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalci2.java
More file actions
173 lines (156 loc) · 3.16 KB
/
Calci2.java
File metadata and controls
173 lines (156 loc) · 3.16 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import java.awt.*;
import java.awt.event.*;
class Demo extends Frame {
Button b1, b2, b3, b4;
Panel p;
TextField t1, t2, t3;
Label l1, l2, l3;
Font f;
class E extends WindowAdapter
{
public void windowClosing( WindowEvent e)
{
dispose();
}
}
class A implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
try {
String s1=t1.getText();
String s2=t2.getText();
int n1=Integer.parseInt(s1);
int n2=Integer.parseInt(s2);
int n=n1+n2;
//t3.setText(String.valueOf(n));
String s3=(String.valueOf(n));
t3.setText(s3);
}
catch(Exception ex)
{
t3.setText(ex.getMessage());
}
}
}
class B implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
try {
String s1=t1.getText();
String s2=t2.getText();
int n1=Integer.parseInt(s1);
int n2=Integer.parseInt(s2);
int n=n1-n2;
t3.setText(String.valueOf(n));
}
catch(Exception ex)
{
t3.setText(ex.getMessage());
}
}
}
class C implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
try {
String s1=t1.getText();
String s2=t2.getText();
int n1=Integer.parseInt(s1);
int n2=Integer.parseInt(s2);
int n=n1*n2;
t3.setText(String.valueOf(n));
}
catch(Exception ex)
{
t3.setText(ex.getMessage());
}
}
}
class D implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
try {
String s1=t1.getText();
String s2=t2.getText();
int n1=Integer.parseInt(s1);
int n2=Integer.parseInt(s2);
int n=n1/n2;
t3.setText(String.valueOf(n));
}
catch(Exception ex)
{
t3.setText(ex.getMessage());
}
}
}
Demo() {
setSize(500, 500);
setTitle("Calci");
setBackground(Color.orange);
setLayout(null);
addWindowListener(new E());
f=new Font("Arial",0,20);
p = new Panel();
p.setLayout(null);
p.setBounds(40, 60, 410, 330);
p.setBackground(Color.blue);
add(p);
l1 = new Label("1st no");
l1.setBounds(30, 30, 80, 40);
l1.setForeground(Color.white);
l1.setFont(f);
p.add(l1);
l2 = new Label("2nd no");
l2.setBounds(30, 150, 80, 40);
l2.setForeground(Color.white);
l2.setFont(f);
p.add(l2);
b1 = new Button("+");
b1.setBounds(30, 250, 40, 40);
b1.addActionListener(new A());
b1.setFont(f);
p.add(b1);
b2 = new Button("-");
b2.setBounds(120, 250, 40, 40);
b2.setFont(f);
b2.addActionListener(new B());
p.add(b2);
b3 = new Button("*");
b3.setBounds(220, 250, 40, 40);
b3.setFont(f);
b3.addActionListener(new C());
p.add(b3);
b4 = new Button("/");
b4.setBounds(310, 250, 40, 40);
b4.setFont(f);
b4.addActionListener(new D());
p.add(b4);
t1 = new TextField();
t1.setBounds(280, 30, 80, 40);
t1.setForeground(Color.red);
t1.setFont(f);
p.add(t1);
t2 = new TextField();
t2.setBounds(280, 150, 80, 40);
t2.setForeground(Color.red);
t2.setFont(f);
p.add(t2);
l3 = new Label("Answer");
l3.setBounds(60, 410, 50, 60);
l3.setFont(f);
add(l3);
t3 = new TextField();
t3.setBounds(340, 420, 90, 40);
t3.setFont(f);
add(t3);
}
}
public class Calci2 {
public static void main(String[] args) {
new Demo().setVisible(true);
}
}