-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalcu.java
More file actions
292 lines (262 loc) · 8.45 KB
/
calcu.java
File metadata and controls
292 lines (262 loc) · 8.45 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class calcu extends JFrame {
JFrame frame = new JFrame ("ANGELY'S CALCULATOR");
JButton num7 = new JButton("7");
JButton num8 = new JButton("8");
JButton num9 = new JButton("9");
JButton num4 = new JButton("4");
JButton num5 = new JButton("5");
JButton num6 = new JButton("6");
JButton num1 = new JButton("1");
JButton num2 = new JButton("2");
JButton num3 = new JButton("3");
JButton num0 = new JButton("0");
JButton equal = new JButton("=");
JButton add = new JButton("+");
JButton subt = new JButton("-");
JButton mul = new JButton("x");
JButton divi = new JButton("/");
JButton perce=new JButton("%");
JButton clear=new JButton ("DEL");
double number, answer;
JTextField result = new JTextField(10);
Boolean addBool = false;
Boolean mulBool = false;
Boolean diviBool = false;
Boolean subtBool = false;
Boolean percentBool = false;
String display = "";
public calcu() {
result.setHorizontalAlignment(JTextField.RIGHT);
result.setFont(new Font("Montserrat", Font.BOLD,30));
num7.setBackground(Color.white);
num7.setFont(new Font("Montserrat", Font.BOLD,30));
num8.setBackground(Color.white);
num8.setFont(new Font("Montserrat", Font.BOLD,30));
num9.setBackground(Color.white);
num9.setFont(new Font("Montserrat", Font.BOLD,30));
num4.setBackground(Color.white);
num4.setFont(new Font("Montserrat", Font.BOLD,30));
num5.setBackground(Color.white);
num5.setFont(new Font("Montserrat", Font.BOLD,30));
num6.setBackground(Color.white);
num6.setFont(new Font("Montserrat", Font.BOLD,30));
num1.setBackground(Color.white);
num1.setFont(new Font("Montserrat", Font.BOLD,30));
num2.setBackground(Color.white);
num2.setFont(new Font("Montserrat", Font.BOLD,30));
num3.setBackground(Color.white);
num3.setFont(new Font("Montserrat", Font.BOLD,30));
num0.setBackground(Color.white);
num0.setFont(new Font("Montserrat", Font.BOLD,30));
equal.setBackground(Color.orange);
equal.setFont(new Font("Montserrat", Font.BOLD,30));
add.setBackground(Color.white);
add.setFont(new Font("Montserrat", Font.BOLD,30));
subt.setBackground(Color.white);
subt.setFont(new Font("Montserrat", Font.BOLD,30));
mul.setBackground(Color.white);
mul.setFont(new Font("Montserrat", Font.BOLD,30));
divi.setBackground(Color.white);
divi.setFont(new Font("Montserrat", Font.BOLD,30));
perce.setBackground(Color.WHITE);
perce.setFont(new Font("Montserrat", Font.BOLD,30));
clear.setBackground(Color.orange);
clear.setFont(new Font("Montserrat", Font.BOLD,20));
result.setBackground(Color.white);
result.setEditable(false);
frame.add(result);
result.setBounds(20,20,270,90);
frame.add(num7);
num7.setBounds(20,180,60,40);
frame.add(num8);
num8.setBounds(90,180,60,40);
frame.add(num9);
num9.setBounds(160,180,60,40);
frame.add(num4);
num4.setBounds(20,230,60,40);
frame.add(num5);
num5.setBounds(90,230,60,40);
frame.add(num6);
num6.setBounds(160,230,60,40);
frame.add(num1);
num1.setBounds(20,280,60,40);
frame.add(num2);
num2.setBounds(90,280,60,40);
frame.add(num3);
num3.setBounds(160,280,60,40);
frame.add(num0);
num0.setBounds(20,330,60,40);
frame.add(equal);
equal.setBounds(90,330,200,40);
frame.add(add);
add.setBounds(230,180,60,40);
frame.add(subt);
subt.setBounds(230,230,60,40);
frame.add(mul);
mul.setBounds(230,280,60,40);
frame.add(divi);
divi.setBounds(230,130,60,40);
frame.add(perce);
perce.setBounds(160,130,60,40);
frame.add(clear);
clear.setBounds(20,130,130,40);
num1.addActionListener(new numberone());
num2.addActionListener(new numbertwo());
num3.addActionListener(new numberthree());
num4.addActionListener(new numberfour());
num5.addActionListener(new numberfive());
num6.addActionListener(new numbersix());
num7.addActionListener(new numberseven());
num8.addActionListener(new numbereight());
num9.addActionListener(new numbernine());
num0.addActionListener(new numberzero());
equal.addActionListener(new equals());
add.addActionListener(new addition());
subt.addActionListener(new subtract());
mul.addActionListener(new multiply());
divi.addActionListener(new divide());
perce.addActionListener( new percentage());
clear.addActionListener(new delete());
frame.getContentPane().setBackground(Color.black);
frame.setLayout(null);
frame.setSize(330,430);
frame.setVisible(true);
}
public class numberone implements ActionListener {
public void actionPerformed(ActionEvent e) {
display = result.getText();
result.setText(display + "1");
}
}
public class numbertwo implements ActionListener {
public void actionPerformed(ActionEvent e) {
display = result.getText();
result.setText(display + "2");
}
}
public class numberthree implements ActionListener {
public void actionPerformed(ActionEvent e) {
display = result.getText();
result.setText(display + "3");
}
}
public class numberfour implements ActionListener {
public void actionPerformed(ActionEvent e) {
display = result.getText();
result.setText(display + "4");
}
}
public class numberfive implements ActionListener {
public void actionPerformed(ActionEvent e) {
display = result.getText();
result.setText(display + "5");
}
}
public class numbersix implements ActionListener {
public void actionPerformed(ActionEvent e) {
display = result.getText();
result.setText(display + "6");
}
}
public class numberseven implements ActionListener {
public void actionPerformed(ActionEvent e) {
display = result.getText();
result.setText(display + "7");
}
}
public class numbereight implements ActionListener {
public void actionPerformed(ActionEvent e) {
display = result.getText();
result.setText(display + "8");
}
}
public class numbernine implements ActionListener {
public void actionPerformed(ActionEvent e) {
display = result.getText();
result.setText(display + "9");
}
}
public class numberzero implements ActionListener {
public void actionPerformed(ActionEvent e) {
display = result.getText();
result.setText(display + "0");
}
}
public class addition implements ActionListener {
public void actionPerformed(ActionEvent e) {
number = Double.parseDouble(result.getText());
result.setText("");
addBool = true;
}
}
public class subtract implements ActionListener {
public void actionPerformed(ActionEvent e) {
number = Double.parseDouble(result.getText());
result.setText("");
subtBool = true; }
}
public class divide implements ActionListener {
public void actionPerformed(ActionEvent e) {
number = Double.parseDouble(result.getText());
result.setText("");
diviBool = true;
}
}
public class multiply implements ActionListener {
public void actionPerformed(ActionEvent e) {
number = Double.parseDouble(result.getText());
result.setText("");
mulBool = true;
}
}
public class percentage implements ActionListener {
public void actionPerformed(ActionEvent e) {
number = Double.parseDouble(result.getText());
result.setText("");
percentBool = true;
}
}
public class delete implements ActionListener {
public void actionPerformed(ActionEvent e) {
result.setText("");
addBool = false;
mulBool = false;
subtBool = false;
diviBool = false;
percentBool = false;
answer = 0;
number=0;
}
}
public class equals implements ActionListener {
public void actionPerformed(ActionEvent e) {
answer = Double.parseDouble(result.getText());
if (addBool == true)
answer = number + answer;
else if (subtBool == true)
answer = number - answer;
else if (mulBool == true)
answer = number * answer;
else if (diviBool == true)
answer = number / answer;
else if (percentBool == true)
answer = number % answer;
result.setText(Double.toString(answer));
addBool = false;
mulBool = false;
subtBool = false;
diviBool = false;
percentBool = false;
}
}
public static void main(String[] args) {
calcu c = new calcu();
}
}