forked from Mhassanbughio/Calculator-java-Fx
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Calculator.java
683 lines (634 loc) · 25.2 KB
/
Calculator.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
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
package com.houarizegai.calculator;
import java.awt.Cursor;
import java.awt.Font;
import java.util.regex.Pattern;
import java.awt.Color;
import javax.swing.*;
import java.lang.Math;
public class Calculator {
private static final int WINDOW_WIDTH = 410;
private static final int WINDOW_HEIGHT = 600;
private static final int BUTTON_WIDTH = 80; // Button width
private static final int BUTTON_HEIGHT = 70; // Button height
private static final int MARGIN_X = 20;
private static final int MARGIN_Y = 60;
private JFrame window; // Main window
private JTextField inText; // Input text
private JButton btnC, btnBack, btnMod, btnDiv, btn7, btn8, btn9,
btnMul, btn4, btn5, btn6, btnSub, btn1, btn2, btn3, btnAdd, btnPoint, btn0, btnEqual, btnRoot, btnPower, btnLog, btnSwitchThemes, btnSwitchToScientificMode;
private char opt = ' '; // Save the operator
private boolean go = true; // For calculate with Opt != (=)
private boolean addWrite = true; // Racordé des Nombres dans l'Affichage
private double val = 0; // Save value typed for calculation
private boolean isToggleColorSelected = false;
private boolean isScientificMode = false;
/*
Mx Calculator:
X = Row
Y = Column
+-------------------+
| +-----------+ | y[0]
| | | |
| +-----------+ |
| |
| C <- % / | y[1]
| 7 8 9 * | y[2]
| 4 5 6 - | y[3]
| 1 2 3 + | y[4]
| . 0 = | y[5]
+-------------------+
x[0] x[1] x[2] x[3]
*/
/*
+-------------------+
| +-----------+ | y[0]
| | | |
| +-----------+ |
| |
| 0 1 1 3 | y[1]
| 4 5 6 7 | y[2]
| 8 9 10 11 | y[3]
| 12 13 14 15 | y[4]
| 16 17 18 | y[5]
+-------------------+
x[0] x[1] x[2] x[3]
*/
private Calculator() {
window = new JFrame("Calculator");
window.setSize(WINDOW_WIDTH, WINDOW_HEIGHT); // Set the width and the Height of the window
window.setLocationRelativeTo(null); // Move Window To Center
// Button fonts
Font btnFont = new Font("Comic Sans MS", Font.PLAIN, 28);
Font smallTxtBtnFont = new Font("Comic Sans MS", Font.PLAIN, 24);
btnSwitchThemes = new JButton();
btnSwitchThemes.setBounds(230, 30, 140, 18);
btnSwitchThemes.setText("Toggle colors");
btnSwitchThemes.setBackground(Color.GREEN.darker());
btnSwitchThemes.setForeground(Color.WHITE);
btnSwitchThemes.setCursor(new Cursor(Cursor.HAND_CURSOR));
btnSwitchThemes.addActionListener(event -> onSwitchTheme());
window.add(btnSwitchThemes);
btnSwitchToScientificMode = new JButton();
btnSwitchToScientificMode.setBounds(30, 30, 140, 18);
btnSwitchToScientificMode.setText("Scientific Mode");
btnSwitchToScientificMode.setBackground(Color.BLUE.darker());
btnSwitchToScientificMode.setForeground(Color.WHITE);
btnSwitchToScientificMode.setCursor(new Cursor(Cursor.HAND_CURSOR));
btnSwitchToScientificMode.addActionListener(event -> onShowScientificMode());
window.add(btnSwitchToScientificMode);
int j = -1;
int k = -1;
int[] x = {MARGIN_X, MARGIN_X + 90, 200, 290, 380};
int[] y = {MARGIN_Y, MARGIN_Y + 100, MARGIN_Y + 180, MARGIN_Y + 260, MARGIN_Y + 340, MARGIN_Y + 420};
inText = new JTextField("0");
inText.setBounds(x[0], y[0], 350, 70);
inText.setEditable(false);
inText.setBackground(Color.WHITE);
inText.setFont(new Font("Comic Sans MS", Font.PLAIN, 33));
window.add(inText);
btnC = new JButton("C");
btnC.setBounds(x[0], y[1], BUTTON_WIDTH, BUTTON_HEIGHT);
btnC.setFont(btnFont);
btnC.setCursor(new Cursor(Cursor.HAND_CURSOR));
btnC.addActionListener(event -> {
repaintFont();
inText.setText("0");
opt = ' ';
val = 0;
});
window.add(btnC);
btnBack = new JButton("<-");
btnBack.setBounds(x[1], y[1], BUTTON_WIDTH, BUTTON_HEIGHT);
btnBack.setFont(btnFont);
btnBack.setCursor(new Cursor(Cursor.HAND_CURSOR));
btnBack.addActionListener(event -> {
repaintFont();
String str = inText.getText();
StringBuilder str2 = new StringBuilder();
for (int i = 0; i < (str.length() - 1); i++) {
str2.append(str.charAt(i));
}
if (str2.toString().equals("")) {
inText.setText("0");
} else {
inText.setText(str2.toString());
}
});
window.add(btnBack);
btnMod = new JButton("%");
btnMod.setBounds(x[2], y[1], BUTTON_WIDTH, BUTTON_HEIGHT);
btnMod.setFont(btnFont);
btnMod.setCursor(new Cursor(Cursor.HAND_CURSOR));
btnMod.addActionListener(event -> {
repaintFont();
if (Pattern.matches("([-]?\\d+[.]\\d*)|(\\d+)", inText.getText()))
if (go) {
val = calc(val, inText.getText(), opt);
if (Pattern.matches("[-]?[\\d]+[.][0]*", String.valueOf(val))) {
inText.setText(String.valueOf((int) val));
} else {
inText.setText(String.valueOf(val));
}
opt = '%';
go = false;
addWrite = false;
}
});
window.add(btnMod);
btnDiv = new JButton("/");
btnDiv.setBounds(x[3], y[1], BUTTON_WIDTH, BUTTON_HEIGHT);
btnDiv.setFont(btnFont);
btnDiv.setCursor(new Cursor(Cursor.HAND_CURSOR));
btnDiv.addActionListener(event -> {
repaintFont();
if (Pattern.matches("([-]?\\d+[.]\\d*)|(\\d+)", inText.getText()))
if (go) {
val = calc(val, inText.getText(), opt);
if (Pattern.matches("[-]?[\\d]+[.][0]*", String.valueOf(val))) {
inText.setText(String.valueOf((int) val));
} else {
inText.setText(String.valueOf(val));
}
opt = '/';
go = false;
addWrite = false;
} else {
opt = '/';
}
});
window.add(btnDiv);
btn7 = new JButton("7");
btn7.setBounds(x[0], y[2], BUTTON_WIDTH, BUTTON_HEIGHT);
btn7.setFont(btnFont);
btn7.setCursor(new Cursor(Cursor.HAND_CURSOR));
btn7.addActionListener(event -> {
repaintFont();
if (addWrite) {
if (Pattern.matches("[0]*", inText.getText())) {
inText.setText("7");
} else {
inText.setText(inText.getText() + "7");
}
} else {
inText.setText("7");
addWrite = true;
}
go = true;
});
window.add(btn7);
btn8 = new JButton("8");
btn8.setBounds(x[1], y[2], BUTTON_WIDTH, BUTTON_HEIGHT);
btn8.setFont(btnFont);
btn8.setCursor(new Cursor(Cursor.HAND_CURSOR));
btn8.addActionListener(event -> {
repaintFont();
if (addWrite) {
if (Pattern.matches("[0]*", inText.getText())) {
inText.setText("8");
} else {
inText.setText(inText.getText() + "8");
}
} else {
inText.setText("8");
addWrite = true;
}
go = true;
});
window.add(btn8);
btn9 = new JButton("9");
btn9.setBounds(x[2], y[2], BUTTON_WIDTH, BUTTON_HEIGHT);
btn9.setFont(btnFont);
btn9.setCursor(new Cursor(Cursor.HAND_CURSOR));
btn9.addActionListener(event -> {
repaintFont();
if (addWrite) {
if (Pattern.matches("[0]*", inText.getText())) {
inText.setText("9");
} else {
inText.setText(inText.getText() + "9");
}
} else {
inText.setText("9");
addWrite = true;
}
go = true;
});
window.add(btn9);
btnMul = new JButton("*");
btnMul.setBounds(x[3], y[2], BUTTON_WIDTH, BUTTON_HEIGHT);
btnMul.setFont(btnFont);
btnMul.setCursor(new Cursor(Cursor.HAND_CURSOR));
btnMul.addActionListener(event -> {
repaintFont();
if (Pattern.matches("([-]?\\d+[.]\\d*)|(\\d+)", inText.getText()))
if (go) {
val = calc(val, inText.getText(), opt);
if (Pattern.matches("[-]?[\\d]+[.][0]*", String.valueOf(val))) {
inText.setText(String.valueOf((int) val));
} else {
inText.setText(String.valueOf(val));
}
opt = '*';
go = false;
addWrite = false;
} else {
opt = '*';
}
});
window.add(btnMul);
btn4 = new JButton("4");
btn4.setBounds(x[0], y[3], BUTTON_WIDTH, BUTTON_HEIGHT);
btn4.setFont(btnFont);
btn4.setCursor(new Cursor(Cursor.HAND_CURSOR));
btn4.addActionListener(event -> {
repaintFont();
if (addWrite) {
if (Pattern.matches("[0]*", inText.getText())) {
inText.setText("4");
} else {
inText.setText(inText.getText() + "4");
}
} else {
inText.setText("4");
addWrite = true;
}
go = true;
});
window.add(btn4);
btn5 = new JButton("5");
btn5.setBounds(x[1], y[3], BUTTON_WIDTH, BUTTON_HEIGHT);
btn5.setFont(btnFont);
btn5.setCursor(new Cursor(Cursor.HAND_CURSOR));
btn5.addActionListener(event -> {
repaintFont();
if (addWrite) {
if (Pattern.matches("[0]*", inText.getText())) {
inText.setText("5");
} else {
inText.setText(inText.getText() + "5");
}
} else {
inText.setText("5");
addWrite = true;
}
go = true;
});
window.add(btn5);
btn6 = new JButton("6");
btn6.setBounds(x[2], y[3], BUTTON_WIDTH, BUTTON_HEIGHT);
btn6.setFont(btnFont);
btn6.setCursor(new Cursor(Cursor.HAND_CURSOR));
btn6.addActionListener(event -> {
repaintFont();
if (addWrite) {
if (Pattern.matches("[0]*", inText.getText())) {
inText.setText("6");
} else {
inText.setText(inText.getText() + "6");
}
} else {
inText.setText("6");
addWrite = true;
}
go = true;
});
window.add(btn6);
btnSub = new JButton("-");
btnSub.setBounds(x[3], y[3], BUTTON_WIDTH, BUTTON_HEIGHT);
btnSub.setFont(btnFont);
btnSub.setCursor(new Cursor(Cursor.HAND_CURSOR));
btnSub.addActionListener(event -> {
repaintFont();
if (Pattern.matches("([-]?\\d+[.]\\d*)|(\\d+)", inText.getText()))
if (go) {
val = calc(val, inText.getText(), opt);
if (Pattern.matches("[-]?[\\d]+[.][0]*", String.valueOf(val))) {
inText.setText(String.valueOf((int) val));
} else {
inText.setText(String.valueOf(val));
}
opt = '-';
go = false;
addWrite = false;
} else {
opt = '-';
}
});
window.add(btnSub);
btn1 = new JButton("1");
btn1.setBounds(x[0], y[4], BUTTON_WIDTH, BUTTON_HEIGHT);
btn1.setFont(btnFont);
btn1.setCursor(new Cursor(Cursor.HAND_CURSOR));
btn1.addActionListener(event -> {
repaintFont();
if (addWrite) {
if (Pattern.matches("[0]*", inText.getText())) {
inText.setText("1");
} else {
inText.setText(inText.getText() + "1");
}
} else {
inText.setText("1");
addWrite = true;
}
go = true;
});
window.add(btn1);
btn2 = new JButton("2");
btn2.setBounds(x[1], y[4], BUTTON_WIDTH, BUTTON_HEIGHT);
btn2.setFont(btnFont);
btn2.setCursor(new Cursor(Cursor.HAND_CURSOR));
btn2.addActionListener(event -> {
repaintFont();
if (addWrite) {
if (Pattern.matches("[0]*", inText.getText())) {
inText.setText("2");
} else {
inText.setText(inText.getText() + "2");
}
} else {
inText.setText("2");
addWrite = true;
}
go = true;
});
window.add(btn2);
btn3 = new JButton("3");
btn3.setBounds(x[2], y[4], BUTTON_WIDTH, BUTTON_HEIGHT);
btn3.setFont(btnFont);
btn3.setCursor(new Cursor(Cursor.HAND_CURSOR));
btn3.addActionListener(event -> {
repaintFont();
if (addWrite) {
if (Pattern.matches("[0]*", inText.getText())) {
inText.setText("3");
} else {
inText.setText(inText.getText() + "3");
}
} else {
inText.setText("3");
addWrite = true;
}
go = true;
});
window.add(btn3);
btnAdd = new JButton("+");
btnAdd.setBounds(x[3], y[4], BUTTON_WIDTH, BUTTON_HEIGHT);
btnAdd.setFont(btnFont);
btnAdd.setCursor(new Cursor(Cursor.HAND_CURSOR));
btnAdd.addActionListener(event -> {
repaintFont();
if (Pattern.matches("([-]?\\d+[.]\\d*)|(\\d+)", inText.getText()))
if (go) {
val = calc(val, inText.getText(), opt);
if (Pattern.matches("[-]?[\\d]+[.][0]*", String.valueOf(val))) {
inText.setText(String.valueOf((int) val));
} else {
inText.setText(String.valueOf(val));
}
opt = '+';
go = false;
addWrite = false;
} else {
opt = '+';
}
});
window.add(btnAdd);
btnPoint = new JButton(".");
btnPoint.setBounds(x[0], y[5], BUTTON_WIDTH, BUTTON_HEIGHT);
btnPoint.setFont(new Font("Comic Sans MS", Font.BOLD, 32));
btnPoint.setCursor(new Cursor(Cursor.HAND_CURSOR));
btnPoint.addActionListener(event -> {
repaintFont();
if (addWrite) {
inText.setText(inText.getText() + ".");
} else {
inText.setText("0.");
addWrite = true;
}
go = true;
});
window.add(btnPoint);
btn0 = new JButton("0");
btn0.setBounds(x[1], y[5], BUTTON_WIDTH, BUTTON_HEIGHT);
btn0.setFont(btnFont);
btn0.setCursor(new Cursor(Cursor.HAND_CURSOR));
btn0.addActionListener(event -> {
repaintFont();
if (addWrite) {
if (Pattern.matches("[0]*", inText.getText())) {
inText.setText("0");
} else {
inText.setText(inText.getText() + "0");
}
} else {
inText.setText("0");
addWrite = true;
}
go = true;
});
window.add(btn0);
btnEqual = new JButton("=");
btnEqual.setBounds(x[2], y[5], 2 * BUTTON_WIDTH + 10, BUTTON_HEIGHT);
btnEqual.setFont(btnFont);
btnEqual.setCursor(new Cursor(Cursor.HAND_CURSOR));
btnEqual.addActionListener(event -> {
if (Pattern.matches("([-]?\\d+[.]\\d*)|(\\d+)", inText.getText()))
if (go) {
val = calc(val, inText.getText(), opt);
if (Pattern.matches("[-]?[\\d]+[.][0]*", String.valueOf(val))) {
inText.setText(String.valueOf((int) val));
} else {
inText.setText(String.valueOf(val));
}
opt = '=';
addWrite = false;
}
});
window.add(btnEqual);
btnRoot = new JButton("√");
btnRoot.setBounds(x[4], y[1], BUTTON_WIDTH, BUTTON_HEIGHT);
btnRoot.setFont(btnFont);
btnRoot.setCursor(new Cursor(Cursor.HAND_CURSOR));
btnRoot.addActionListener(event -> {
if (Pattern.matches("([-]?\\d+[.]\\d*)|(\\d+)", inText.getText()))
if (go) {
val = Math.sqrt(Double.parseDouble(inText.getText()));
if (Pattern.matches("[-]?[\\d]+[.][0]*", String.valueOf(val))) {
inText.setText(String.valueOf((int) val));
} else {
inText.setText(String.valueOf(val));
}
opt = '√';
addWrite = false;
}
});
btnRoot.setVisible(false);
window.add(btnRoot);
btnPower = new JButton("pow");
btnPower.setBounds(x[4], y[2], BUTTON_WIDTH, BUTTON_HEIGHT);
btnPower.setFont(smallTxtBtnFont);
btnPower.setCursor(new Cursor(Cursor.HAND_CURSOR));
btnPower.addActionListener(event -> {
repaintFont();
if (Pattern.matches("([-]?\\d+[.]\\d*)|(\\d+)", inText.getText()))
if (go) {
val = calc(val, inText.getText(), opt);
if (Pattern.matches("[-]?[\\d]+[.][0]*", String.valueOf(val))) {
inText.setText(String.valueOf((int) val));
} else {
inText.setText(String.valueOf(val));
}
opt = '^';
go = false;
addWrite = false;
} else {
opt = '^';
}
});
btnPower.setVisible(false);
window.add(btnPower);
btnLog = new JButton("log");
btnLog.setBounds(x[4], y[3], BUTTON_WIDTH, BUTTON_HEIGHT);
btnLog.setFont(smallTxtBtnFont);
btnLog.setCursor(new Cursor(Cursor.HAND_CURSOR));
btnLog.addActionListener(event -> {
if (Pattern.matches("([-]?\\d+[.]\\d*)|(\\d+)", inText.getText()))
if (go) {
val = Math.log(Double.parseDouble(inText.getText()));
if (Pattern.matches("[-]?[\\d]+[.][0]*", String.valueOf(val))) {
inText.setText(String.valueOf((int) val));
} else {
inText.setText(String.valueOf(val));
}
opt = 'l';
addWrite = false;
}
});
btnLog.setVisible(false);
window.add(btnLog);
window.setLayout(null);
window.setResizable(false);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // If Click into The Red Button => End The Processus
window.setVisible(true);
}
private double calc(double x, String input, char opt) {
inText.setFont(inText.getFont().deriveFont(Font.BOLD));
double y = Double.parseDouble(input);
if (opt == '+') {
return x + y;
} else if (opt == '-') {
return x - y;
} else if (opt == '*') {
return x * y;
} else if (opt == '/') {
return x / y;
} else if (opt == '%') {
return x % y;
} else if (opt == '^') {
return Math.pow(x, y);
}
inText.setFont(inText.getFont().deriveFont(Font.PLAIN));
return y;
}
private void repaintFont() {
inText.setFont(inText.getFont().deriveFont(Font.PLAIN));
}
private void onSwitchTheme() {
if (isToggleColorSelected) {
btnSwitchThemes.setText("Toggle colors");
btnSwitchThemes.setBackground(Color.GREEN.darker());
btnSwitchThemes.setForeground(Color.WHITE);
btnC.setBackground(null);
btnBack.setBackground(null);
btnMod.setBackground(null);
btnDiv.setBackground(null);
btnMul.setBackground(null);
btnSub.setBackground(null);
btnAdd.setBackground(null);
btnRoot.setBackground(null);
btnLog.setBackground(null);
btnPower.setBackground(null);
btnEqual.setBackground(null);
btn0.setBackground(null);
btn1.setBackground(null);
btn2.setBackground(null);
btn3.setBackground(null);
btn4.setBackground(null);
btn5.setBackground(null);
btn6.setBackground(null);
btn7.setBackground(null);
btn8.setBackground(null);
btn9.setBackground(null);
btnPoint.setBackground(null);
btnC.setForeground(Color.BLACK);
btnBack.setForeground(Color.BLACK);
btnMod.setForeground(Color.BLACK);
btnDiv.setForeground(Color.BLACK);
btnMul.setForeground(Color.BLACK);
btnSub.setForeground(Color.BLACK);
btnAdd.setForeground(Color.BLACK);
btnEqual.setForeground(Color.BLACK);
btnLog.setForeground(Color.BLACK);
btnPower.setForeground(Color.BLACK);
btnRoot.setForeground(Color.BLACK);
isToggleColorSelected = false;
} else {
btnSwitchThemes.setText("Untoggle colors");
btnSwitchThemes.setBackground(null);
btnSwitchThemes.setForeground(Color.BLACK);
btnC.setBackground(Color.RED);
btnBack.setBackground(Color.ORANGE);
btnMod.setBackground(Color.GREEN);
btnDiv.setBackground(Color.PINK);
btnMul.setBackground(Color.PINK);
btnSub.setBackground(Color.PINK);
btnAdd.setBackground(Color.PINK);
btnRoot.setBackground(Color.PINK);
btnLog.setBackground(Color.PINK);
btnPower.setBackground(Color.PINK);
btnEqual.setBackground(Color.BLUE);
btn0.setBackground(Color.WHITE);
btn1.setBackground(Color.WHITE);
btn2.setBackground(Color.WHITE);
btn3.setBackground(Color.WHITE);
btn4.setBackground(Color.WHITE);
btn5.setBackground(Color.WHITE);
btn6.setBackground(Color.WHITE);
btn7.setBackground(Color.WHITE);
btn8.setBackground(Color.WHITE);
btn9.setBackground(Color.WHITE);
btnPoint.setBackground(Color.WHITE);
btnC.setForeground(Color.WHITE);
btnBack.setForeground(Color.WHITE);
btnMod.setForeground(Color.WHITE);
btnDiv.setForeground(Color.WHITE);
btnMul.setForeground(Color.WHITE);
btnSub.setForeground(Color.WHITE);
btnAdd.setForeground(Color.WHITE);
btnEqual.setForeground(Color.WHITE);
btnLog.setForeground(Color.WHITE);
btnPower.setForeground(Color.WHITE);
btnRoot.setForeground(Color.WHITE);
isToggleColorSelected = true;
}
}
private void onShowScientificMode() {
if (isScientificMode) {
window.setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
btnRoot.setVisible(false);
btnPower.setVisible(false);
btnLog.setVisible(false);
isScientificMode = false;
} else {
window.setSize(WINDOW_WIDTH + 80, WINDOW_HEIGHT);
btnRoot.setVisible(true);
btnPower.setVisible(true);
btnLog.setVisible(true);
isScientificMode = true;
}
}
public static void main(String[] args) {
new Calculator();
}
}