-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc.java
611 lines (542 loc) · 28.8 KB
/
calc.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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author DANTE
*/
public class calc extends javax.swing.JFrame {
double num;
double ans;
int calculation;
public calc() {
initComponents();
/*on.setEnabled(false);*/
}
public void operation(){
switch(calculation) {
case 1:
ans = num + Double.parseDouble(calc.getText());
calc.setText(Double.toString(ans));
break;
case 2:
ans = num - Double.parseDouble(calc.getText());
calc.setText(Double.toString(ans));
break;
case 3:
ans = num / Double.parseDouble(calc.getText());
calc.setText(Double.toString(ans));
break;
case 4:
ans = num * Double.parseDouble(calc.getText());
calc.setText(Double.toString(ans));
break;
}
}
public void enable() {
calc.setEnabled(true);
on.setEnabled(false);
off.setEnabled(true);
rub.setEnabled(true);
clear.setEnabled(true);
plus.setEnabled(true);
seven.setEnabled(true);
eight.setEnabled(true);
nine.setEnabled(true);
minus.setEnabled(true);
four.setEnabled(true);
five.setEnabled(true);
six.setEnabled(true);
div.setEnabled(true);
one.setEnabled(true);
two.setEnabled(true);
three.setEnabled(true);
mult.setEnabled(true);
zero.setEnabled(true);
point.setEnabled(true);
equals.setEnabled(true);
}
public void freeze() {
calc.setEnabled(false);
on.setEnabled(true);
off.setEnabled(false);
rub.setEnabled(false);
clear.setEnabled(false);
plus.setEnabled(false);
seven.setEnabled(false);
eight.setEnabled(false);
nine.setEnabled(false);
minus.setEnabled(false);
four.setEnabled(false);
five.setEnabled(false);
six.setEnabled(false);
div.setEnabled(false);
one.setEnabled(false);
two.setEnabled(false);
three.setEnabled(false);
mult.setEnabled(false);
zero.setEnabled(false);
point.setEnabled(false);
equals.setEnabled(false);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
buttonGroup1 = new javax.swing.ButtonGroup();
jLabel1 = new javax.swing.JLabel();
calc = new javax.swing.JTextField();
on = new javax.swing.JRadioButton();
off = new javax.swing.JRadioButton();
rub = new javax.swing.JButton();
clear = new javax.swing.JButton();
plus = new javax.swing.JButton();
eight = new javax.swing.JButton();
seven = new javax.swing.JButton();
nine = new javax.swing.JButton();
one = new javax.swing.JButton();
three = new javax.swing.JButton();
five = new javax.swing.JButton();
six = new javax.swing.JButton();
four = new javax.swing.JButton();
two = new javax.swing.JButton();
div = new javax.swing.JButton();
mult = new javax.swing.JButton();
zero = new javax.swing.JButton();
minus = new javax.swing.JButton();
equals = new javax.swing.JButton();
point = new javax.swing.JButton();
show = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("FRADS CALCULATOR APP");
setLocation(new java.awt.Point(500, 250));
setType(java.awt.Window.Type.UTILITY);
jLabel1.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
jLabel1.setText(" FRADS CALCULATOR APP");
calc.setFont(new java.awt.Font("Rockwell Condensed", 1, 24)); // NOI18N
calc.setHorizontalAlignment(javax.swing.JTextField.RIGHT);
calc.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
calcActionPerformed(evt);
}
});
buttonGroup1.add(on);
on.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
on.setText("ON");
on.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
onActionPerformed(evt);
}
});
buttonGroup1.add(off);
off.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
off.setText("OFF");
off.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
offActionPerformed(evt);
}
});
rub.setFont(new java.awt.Font("Rockwell Condensed", 1, 18)); // NOI18N
rub.setText("<--");
rub.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
rubActionPerformed(evt);
}
});
clear.setFont(new java.awt.Font("Rockwell Condensed", 1, 18)); // NOI18N
clear.setText("C");
clear.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
clearActionPerformed(evt);
}
});
plus.setFont(new java.awt.Font("Rockwell Condensed", 1, 18)); // NOI18N
plus.setText("+");
plus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
plusActionPerformed(evt);
}
});
eight.setFont(new java.awt.Font("Rockwell Condensed", 1, 18)); // NOI18N
eight.setText("8");
eight.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
eightActionPerformed(evt);
}
});
seven.setFont(new java.awt.Font("Rockwell Condensed", 1, 18)); // NOI18N
seven.setText("7");
seven.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
sevenActionPerformed(evt);
}
});
nine.setFont(new java.awt.Font("Rockwell Condensed", 1, 18)); // NOI18N
nine.setText("9");
nine.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nineActionPerformed(evt);
}
});
one.setFont(new java.awt.Font("Rockwell Condensed", 1, 18)); // NOI18N
one.setText("1");
one.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
oneActionPerformed(evt);
}
});
three.setFont(new java.awt.Font("Rockwell Condensed", 1, 18)); // NOI18N
three.setText("3");
three.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
threeActionPerformed(evt);
}
});
five.setFont(new java.awt.Font("Rockwell Condensed", 1, 18)); // NOI18N
five.setText("5");
five.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
fiveActionPerformed(evt);
}
});
six.setFont(new java.awt.Font("Rockwell Condensed", 1, 18)); // NOI18N
six.setText("6");
six.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
sixActionPerformed(evt);
}
});
four.setFont(new java.awt.Font("Rockwell Condensed", 1, 18)); // NOI18N
four.setText("4");
four.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
fourActionPerformed(evt);
}
});
two.setFont(new java.awt.Font("Rockwell Condensed", 1, 18)); // NOI18N
two.setText("2");
two.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
twoActionPerformed(evt);
}
});
div.setFont(new java.awt.Font("Rockwell Condensed", 1, 18)); // NOI18N
div.setText("/");
div.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
divActionPerformed(evt);
}
});
mult.setFont(new java.awt.Font("Rockwell Condensed", 1, 18)); // NOI18N
mult.setText("*");
mult.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
multActionPerformed(evt);
}
});
zero.setFont(new java.awt.Font("Rockwell Condensed", 1, 18)); // NOI18N
zero.setText("0");
zero.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
zeroActionPerformed(evt);
}
});
minus.setFont(new java.awt.Font("Rockwell Condensed", 1, 18)); // NOI18N
minus.setText("-");
minus.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
minusActionPerformed(evt);
}
});
equals.setFont(new java.awt.Font("Rockwell Condensed", 1, 18)); // NOI18N
equals.setText("=");
equals.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
equalsActionPerformed(evt);
}
});
point.setFont(new java.awt.Font("Rockwell Condensed", 1, 18)); // NOI18N
point.setText(".");
point.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
pointActionPerformed(evt);
}
});
show.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
show.setForeground(new java.awt.Color(0, 0, 255));
show.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
show.setText("1");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(141, 141, 141)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 364, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(214, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(calc, javax.swing.GroupLayout.PREFERRED_SIZE, 398, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(seven, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(four, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(one, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(zero, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(off)
.addComponent(on))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(two, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(three, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(mult, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(five, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(point, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(six, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(div, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(equals, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(eight, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(nine, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(rub, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(clear, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(plus, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(minus, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addGap(104, 104, 104)
.addComponent(show, javax.swing.GroupLayout.PREFERRED_SIZE, 190, javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(calc, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(on))
.addGroup(layout.createSequentialGroup()
.addGap(8, 8, 8)
.addComponent(show, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(off)
.addComponent(plus, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(clear, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(rub, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(33, 33, 33)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(eight, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(nine, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(seven, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(minus, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(53, 53, 53)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(five, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(six, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(four, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(div, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(50, 50, 50)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(one, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(three, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(two, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(mult, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 45, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(point, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(zero, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(equals, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(55, 55, 55))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void onActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_onActionPerformed
// TODO add your handling code here:
enable();
}//GEN-LAST:event_onActionPerformed
private void fourActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fourActionPerformed
// TODO add your handling code here:
calc.setText(calc.getText()+ "4");
}//GEN-LAST:event_fourActionPerformed
private void twoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_twoActionPerformed
// TODO add your handling code here:
calc.setText(calc.getText()+ "2");
}//GEN-LAST:event_twoActionPerformed
private void oneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_oneActionPerformed
// TODO add your handling code here:
calc.setText(calc.getText()+ "1");
}//GEN-LAST:event_oneActionPerformed
private void threeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_threeActionPerformed
// TODO add your handling code here:
calc.setText(calc.getText()+ "3");
}//GEN-LAST:event_threeActionPerformed
private void fiveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fiveActionPerformed
// TODO add your handling code here:
calc.setText(calc.getText()+ "5");
}//GEN-LAST:event_fiveActionPerformed
private void sixActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sixActionPerformed
// TODO add your handling code here:
calc.setText(calc.getText()+ "6");
}//GEN-LAST:event_sixActionPerformed
private void sevenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sevenActionPerformed
// TODO add your handling code here:
calc.setText(calc.getText()+ "7");
}//GEN-LAST:event_sevenActionPerformed
private void eightActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_eightActionPerformed
// TODO add your handling code here:
calc.setText(calc.getText()+ "8");
}//GEN-LAST:event_eightActionPerformed
private void nineActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nineActionPerformed
// TODO add your handling code here:
calc.setText(calc.getText()+ "9");
}//GEN-LAST:event_nineActionPerformed
private void pointActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_pointActionPerformed
// TODO add your handling code here:
calc.setText(calc.getText()+ ".");
}//GEN-LAST:event_pointActionPerformed
private void equalsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_equalsActionPerformed
// TODO add your handling code here:
operation();
show.setText("");
}//GEN-LAST:event_equalsActionPerformed
private void multActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_multActionPerformed
// TODO add your handling code here:
num = Double.parseDouble(calc.getText());
calculation = 4;
calc.setText("");
show.setText(num +"*");
}//GEN-LAST:event_multActionPerformed
private void divActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_divActionPerformed
// TODO add your handling code here:
num = Double.parseDouble(calc.getText());
calculation = 3;
calc.setText("");
show.setText(num +"/");
}//GEN-LAST:event_divActionPerformed
private void minusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_minusActionPerformed
// TODO add your handling code here:
num = Double.parseDouble(calc.getText());
calculation = 2;
calc.setText("");
show.setText(num +"-");
}//GEN-LAST:event_minusActionPerformed
private void plusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_plusActionPerformed
// TODO add your handling code here:
num = Double.parseDouble(calc.getText());
calculation = 1;
calc.setText("");
show.setText(num +"+");
}//GEN-LAST:event_plusActionPerformed
private void zeroActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_zeroActionPerformed
// TODO add your handling code here:
calc.setText(calc.getText()+ "0");
}//GEN-LAST:event_zeroActionPerformed
private void clearActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_clearActionPerformed
// TODO add your handling code here:
calc.setText("");
}//GEN-LAST:event_clearActionPerformed
private void calcActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_calcActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_calcActionPerformed
private void offActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_offActionPerformed
// TODO add your handling code here:
freeze();
}//GEN-LAST:event_offActionPerformed
private void rubActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rubActionPerformed
// TODO add your handling code here:
int length = calc.getText().length();
int number = calc.getText().length()- 1;
String store;
if(length > 0) {
StringBuilder back = new StringBuilder(calc.getText());
back.deleteCharAt(number);
store = back.toString();
calc.setText(store);
}
}//GEN-LAST:event_rubActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(calc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(calc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(calc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(calc.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new calc().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JTextField calc;
private javax.swing.JButton clear;
private javax.swing.JButton div;
private javax.swing.JButton eight;
private javax.swing.JButton equals;
private javax.swing.JButton five;
private javax.swing.JButton four;
private javax.swing.JLabel jLabel1;
private javax.swing.JButton minus;
private javax.swing.JButton mult;
private javax.swing.JButton nine;
private javax.swing.JRadioButton off;
private javax.swing.JRadioButton on;
private javax.swing.JButton one;
private javax.swing.JButton plus;
private javax.swing.JButton point;
private javax.swing.JButton rub;
private javax.swing.JButton seven;
private javax.swing.JLabel show;
private javax.swing.JButton six;
private javax.swing.JButton three;
private javax.swing.JButton two;
private javax.swing.JButton zero;
// End of variables declaration//GEN-END:variables
}