1
2
3
4
5
6
7 package rct;
8
9 import javax.swing.ImageIcon;
10
11
12
13
14
15
16
17
18
19
20
21
22 public class Calculator extends javax.swing.JFrame {
23
24
25 public Calculator() {
26
27 initComponents();
28
29 }
30
31
32
33
34
35
36
37 private ImageIcon icon = new ImageIcon(getClass().getResource("/rct/calc.jpg"));
38
39
40
41
42
43
44
45
46
47
48 private void initComponents() {
49
50 buttonGroup1 = new javax.swing.ButtonGroup();
51 popup = new javax.swing.JPopupMenu();
52 jMenuItem2 = new javax.swing.JMenuItem();
53 jMenuItem3 = new javax.swing.JMenuItem();
54 LCDPanel = new javax.swing.JPanel();
55 LCD = new javax.swing.JTextField();
56 buttons = new javax.swing.JPanel();
57 b1 = new javax.swing.JButton();
58 b2 = new javax.swing.JButton();
59 b4 = new javax.swing.JButton();
60 b5 = new javax.swing.JButton();
61 b7 = new javax.swing.JButton();
62 b8 = new javax.swing.JButton();
63 b3 = new javax.swing.JButton();
64 b6 = new javax.swing.JButton();
65 b9 = new javax.swing.JButton();
66 b0 = new javax.swing.JButton();
67 bPlus = new javax.swing.JButton();
68 bDrob = new javax.swing.JButton();
69 bMinus = new javax.swing.JButton();
70 bMultiple = new javax.swing.JButton();
71 bDot = new javax.swing.JButton();
72 bEqual = new javax.swing.JButton();
73 bReset = new javax.swing.JButton();
74 bDelete = new javax.swing.JButton();
75 bSign = new javax.swing.JButton();
76 bKvadrat = new javax.swing.JButton();
77 bKub = new javax.swing.JButton();
78 bKoren = new javax.swing.JButton();
79 LEDS = new javax.swing.JPanel();
80 rbPlus = new javax.swing.JRadioButton();
81 rbMinus = new javax.swing.JRadioButton();
82 rbMultip = new javax.swing.JRadioButton();
83 rbDrob = new javax.swing.JRadioButton();
84 jLabel1 = new javax.swing.JLabel();
85 jLabel2 = new javax.swing.JLabel();
86 jLabel3 = new javax.swing.JLabel();
87 jLabel4 = new javax.swing.JLabel();
88 jToolBar1 = new javax.swing.JToolBar();
89 bExit = new javax.swing.JButton();
90 jRadioButton1 = new javax.swing.JRadioButton();
91
92 jRadioButton1.setVisible(false);
93 bMenuButton = new javax.swing.JButton();
94
95
96
97
98
99
100 jMenuItem2.setText("About");
101 jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
102 public void actionPerformed(java.awt.event.ActionEvent evt) {
103 jMenuItem2ActionPerformed(evt);
104 }
105 });
106
107 popup.add(jMenuItem2);
108
109
110
111
112
113
114 jMenuItem3.setText("Exit");
115 jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
116 public void actionPerformed(java.awt.event.ActionEvent evt) {
117 jMenuItem3ActionPerformed(evt);
118 }
119 });
120
121 popup.add(jMenuItem3);
122
123 setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
124 setTitle("JavaCalculator");
125 setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
126 setIconImage(icon.getImage());
127 setResizable(false);
128 LCDPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));
129 LCD.setBackground(new java.awt.Color(0, 0, 0));
130 LCD.setEditable(false);
131 LCD.setFont(new java.awt.Font("Tahoma", 1, 12));
132 LCD.setForeground(new java.awt.Color(51, 255, 0));
133 LCD.setHorizontalAlignment(javax.swing.JTextField.TRAILING);
134 LCD.setText("0");
135
136 org.jdesktop.layout.GroupLayout LCDPanelLayout = new org.jdesktop.layout.GroupLayout(LCDPanel);
137 LCDPanel.setLayout(LCDPanelLayout);
138 LCDPanelLayout.setHorizontalGroup(
139 LCDPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
140 .add(LCD, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE)
141 );
142 LCDPanelLayout.setVerticalGroup(
143 LCDPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
144 .add(LCD, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
145 );
146
147 buttons.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));
148 b1.setFont(new java.awt.Font("Tahoma", 1, 12));
149 b1.setText("1");
150 b1.setFocusPainted(false);
151 b1.addActionListener(new java.awt.event.ActionListener() {
152 public void actionPerformed(java.awt.event.ActionEvent evt) {
153 b1ActPerf(evt);
154 }
155 });
156
157 b2.setFont(new java.awt.Font("Tahoma", 1, 12));
158 b2.setText("2");
159 b2.setFocusPainted(false);
160 b2.addActionListener(new java.awt.event.ActionListener() {
161 public void actionPerformed(java.awt.event.ActionEvent evt) {
162 b2ActPerf(evt);
163 }
164 });
165
166 b4.setFont(new java.awt.Font("Tahoma", 1, 12));
167 b4.setText("4");
168 b4.setFocusPainted(false);
169 b4.addActionListener(new java.awt.event.ActionListener() {
170 public void actionPerformed(java.awt.event.ActionEvent evt) {
171 b4ActPerf(evt);
172 }
173 });
174
175 b5.setFont(new java.awt.Font("Tahoma", 1, 12));
176 b5.setText("5");
177 b5.setFocusPainted(false);
178 b5.addActionListener(new java.awt.event.ActionListener() {
179 public void actionPerformed(java.awt.event.ActionEvent evt) {
180 b5ActPerf(evt);
181 }
182 });
183
184 b7.setFont(new java.awt.Font("Tahoma", 1, 12));
185 b7.setText("7");
186 b7.setFocusPainted(false);
187 b7.addActionListener(new java.awt.event.ActionListener() {
188 public void actionPerformed(java.awt.event.ActionEvent evt) {
189 b7ActPerf(evt);
190 }
191 });
192
193 b8.setFont(new java.awt.Font("Tahoma", 1, 12));
194 b8.setText("8");
195 b8.setFocusPainted(false);
196 b8.addActionListener(new java.awt.event.ActionListener() {
197 public void actionPerformed(java.awt.event.ActionEvent evt) {
198 b8ActPerf(evt);
199 }
200 });
201
202 b3.setFont(new java.awt.Font("Tahoma", 1, 12));
203 b3.setText("3");
204 b3.setFocusPainted(false);
205 b3.addActionListener(new java.awt.event.ActionListener() {
206 public void actionPerformed(java.awt.event.ActionEvent evt) {
207 b3ActPerf(evt);
208 }
209 });
210
211 b6.setFont(new java.awt.Font("Tahoma", 1, 12));
212 b6.setText("6");
213 b6.setFocusPainted(false);
214 b6.addActionListener(new java.awt.event.ActionListener() {
215 public void actionPerformed(java.awt.event.ActionEvent evt) {
216 b6ActPerf(evt);
217 }
218 });
219
220 b9.setFont(new java.awt.Font("Tahoma", 1, 12));
221 b9.setText("9");
222 b9.setFocusPainted(false);
223 b9.addActionListener(new java.awt.event.ActionListener() {
224 public void actionPerformed(java.awt.event.ActionEvent evt) {
225 b9ActPerf(evt);
226 }
227 });
228
229 b0.setFont(new java.awt.Font("Tahoma", 1, 12));
230 b0.setText("0");
231 b0.setFocusPainted(false);
232 b0.addActionListener(new java.awt.event.ActionListener() {
233 public void actionPerformed(java.awt.event.ActionEvent evt) {
234 b0ActPerf(evt);
235 }
236 });
237
238 bPlus.setFont(new java.awt.Font("Tahoma", 1, 12));
239 bPlus.setText("+");
240 bPlus.setFocusPainted(false);
241 bPlus.addActionListener(new java.awt.event.ActionListener() {
242 public void actionPerformed(java.awt.event.ActionEvent evt) {
243 bPlusActPerf(evt);
244 }
245 });
246
247 bDrob.setFont(new java.awt.Font("Tahoma", 1, 12));
248 bDrob.setText("/");
249 bDrob.setFocusPainted(false);
250 bDrob.addActionListener(new java.awt.event.ActionListener() {
251 public void actionPerformed(java.awt.event.ActionEvent evt) {
252 bDrobActionPerformed(evt);
253 }
254 });
255
256 bMinus.setFont(new java.awt.Font("Tahoma", 1, 12));
257 bMinus.setText("-");
258 bMinus.setFocusPainted(false);
259 bMinus.addActionListener(new java.awt.event.ActionListener() {
260 public void actionPerformed(java.awt.event.ActionEvent evt) {
261 bMinusActionPerformed(evt);
262 }
263 });
264
265 bMultiple.setFont(new java.awt.Font("Tahoma", 1, 12));
266 bMultiple.setText("*");
267 bMultiple.setFocusPainted(false);
268 bMultiple.addActionListener(new java.awt.event.ActionListener() {
269 public void actionPerformed(java.awt.event.ActionEvent evt) {
270 bMultipleActionPerformed(evt);
271 }
272 });
273
274 bDot.setFont(new java.awt.Font("Tahoma", 1, 12));
275 bDot.setText(".");
276 bDot.setFocusPainted(false);
277 bDot.addActionListener(new java.awt.event.ActionListener() {
278 public void actionPerformed(java.awt.event.ActionEvent evt) {
279 bDotActPerf(evt);
280 }
281 });
282
283 bEqual.setFont(new java.awt.Font("Tahoma", 1, 12));
284 bEqual.setText("=");
285 bEqual.setFocusPainted(false);
286 bEqual.addActionListener(new java.awt.event.ActionListener() {
287 public void actionPerformed(java.awt.event.ActionEvent evt) {
288 bEqualActPerf(evt);
289 }
290 });
291
292 bReset.setFont(new java.awt.Font("Tahoma", 0, 10));
293 bReset.setText("\u0421\u0431\u0440\u043e\u0441");
294 bReset.setFocusPainted(false);
295 bReset.addActionListener(new java.awt.event.ActionListener() {
296 public void actionPerformed(java.awt.event.ActionEvent evt) {
297 bResetActionPerformed(evt);
298 }
299 });
300
301 bDelete.setFont(new java.awt.Font("Tahoma", 0, 10));
302 bDelete.setText("<--");
303 bDelete.setFocusPainted(false);
304 bDelete.addActionListener(new java.awt.event.ActionListener() {
305 public void actionPerformed(java.awt.event.ActionEvent evt) {
306 bDeleteActionPerformed(evt);
307 }
308 });
309
310 bSign.setFont(new java.awt.Font("Tahoma", 0, 10));
311 bSign.setText("+/-");
312 bSign.setFocusPainted(false);
313 bSign.addActionListener(new java.awt.event.ActionListener() {
314 public void actionPerformed(java.awt.event.ActionEvent evt) {
315 bSignActionPerformed(evt);
316 }
317 });
318
319 bKvadrat.setFont(new java.awt.Font("Tahoma", 1, 12));
320 bKvadrat.setText("x\u00b2");
321 bKvadrat.setFocusPainted(false);
322 bKvadrat.addActionListener(new java.awt.event.ActionListener() {
323 public void actionPerformed(java.awt.event.ActionEvent evt) {
324 bKvadratActionPerformed(evt);
325 }
326 });
327
328 bKub.setFont(new java.awt.Font("Tahoma", 1, 12));
329 bKub.setText("x\u00b3");
330 bKub.setFocusPainted(false);
331 bKub.addActionListener(new java.awt.event.ActionListener() {
332 public void actionPerformed(java.awt.event.ActionEvent evt) {
333 bKubActionPerformed(evt);
334 }
335 });
336
337 bKoren.setFont(new java.awt.Font("Tahoma", 1, 12));
338 bKoren.setText("\u221ax");
339 bKoren.setFocusPainted(false);
340 bKoren.addActionListener(new java.awt.event.ActionListener() {
341 public void actionPerformed(java.awt.event.ActionEvent evt) {
342 bKorenActionPerformed(evt);
343 }
344 });
345
346 org.jdesktop.layout.GroupLayout buttonsLayout = new org.jdesktop.layout.GroupLayout(buttons);
347 buttons.setLayout(buttonsLayout);
348 buttonsLayout.setHorizontalGroup(
349 buttonsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
350 .add(buttonsLayout.createSequentialGroup()
351 .addContainerGap()
352 .add(buttonsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
353 .add(buttonsLayout.createSequentialGroup()
354 .add(b1)
355 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
356 .add(b2)
357 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
358 .add(b3)
359 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
360 .add(bPlus))
361 .add(buttonsLayout.createSequentialGroup()
362 .add(b4)
363 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
364 .add(b5)
365 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
366 .add(b6)
367 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
368 .add(bMinus))
369 .add(buttonsLayout.createSequentialGroup()
370 .add(buttonsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
371 .add(bDot, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
372 .add(b7, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
373 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
374 .add(buttonsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
375 .add(buttonsLayout.createSequentialGroup()
376 .add(b0)
377 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
378 .add(bEqual)
379 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
380 .add(bMultiple))
381 .add(buttonsLayout.createSequentialGroup()
382 .add(b8)
383 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
384 .add(b9)
385 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
386 .add(bDrob))))
387 .add(buttonsLayout.createSequentialGroup()
388 .add(bReset, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 73, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
389 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
390 .add(bDelete, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 57, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
391 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
392 .add(bSign, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 52, Short.MAX_VALUE))
393 .add(buttonsLayout.createSequentialGroup()
394 .add(bKvadrat, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 64, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
395 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
396 .add(bKub, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 56, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
397 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
398 .add(bKoren, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 62, Short.MAX_VALUE)))
399 .addContainerGap())
400 );
401
402 buttonsLayout.linkSize(new java.awt.Component[] {b1, b2, b3, b4, b5, b6, b7, b8, b9, bDrob, bEqual, bMinus, bMultiple, bPlus}, org.jdesktop.layout.GroupLayout.HORIZONTAL);
403
404 buttonsLayout.setVerticalGroup(
405 buttonsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
406 .add(buttonsLayout.createSequentialGroup()
407 .addContainerGap()
408 .add(buttonsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
409 .add(b1)
410 .add(b2)
411 .add(b3)
412 .add(bPlus))
413 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
414 .add(buttonsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
415 .add(b4)
416 .add(b5)
417 .add(b6)
418 .add(bMinus))
419 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
420 .add(buttonsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
421 .add(b7)
422 .add(b8)
423 .add(b9)
424 .add(bDrob))
425 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
426 .add(buttonsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
427 .add(b0)
428 .add(bMultiple)
429 .add(bDot)
430 .add(bEqual))
431 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
432 .add(buttonsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
433 .add(buttonsLayout.createSequentialGroup()
434 .add(buttonsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
435 .add(bReset)
436 .add(bDelete))
437 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
438 .add(buttonsLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
439 .add(bKoren)
440 .add(bKub)
441 .add(bKvadrat)))
442 .add(bSign))
443 .addContainerGap(17, Short.MAX_VALUE))
444 );
445
446 LEDS.setLayout(new java.awt.GridLayout(2, 4));
447
448 LEDS.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED));
449 buttonGroup1.add(rbPlus);
450 rbPlus.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
451 rbPlus.setEnabled(false);
452 rbPlus.setFocusable(false);
453 rbPlus.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
454 rbPlus.setMargin(new java.awt.Insets(0, 0, 0, 0));
455 LEDS.add(rbPlus);
456
457 buttonGroup1.add(rbMinus);
458 rbMinus.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
459 rbMinus.setEnabled(false);
460 rbMinus.setFocusable(false);
461 rbMinus.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
462 rbMinus.setMargin(new java.awt.Insets(0, 0, 0, 0));
463 LEDS.add(rbMinus);
464
465 buttonGroup1.add(rbMultip);
466 rbMultip.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
467 rbMultip.setEnabled(false);
468 rbMultip.setFocusable(false);
469 rbMultip.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
470 rbMultip.setMargin(new java.awt.Insets(0, 0, 0, 0));
471 LEDS.add(rbMultip);
472
473 buttonGroup1.add(rbDrob);
474 rbDrob.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
475 rbDrob.setEnabled(false);
476 rbDrob.setFocusable(false);
477 rbDrob.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
478 rbDrob.setMargin(new java.awt.Insets(0, 0, 0, 0));
479 LEDS.add(rbDrob);
480
481 jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12));
482 jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
483 jLabel1.setText("+");
484 LEDS.add(jLabel1);
485
486 jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12));
487 jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
488 jLabel2.setText("-");
489 LEDS.add(jLabel2);
490
491 jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12));
492 jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
493 jLabel3.setText("*");
494 LEDS.add(jLabel3);
495
496 jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12));
497 jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
498 jLabel4.setText("/");
499 LEDS.add(jLabel4);
500
501 jToolBar1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
502 jToolBar1.setFloatable(false);
503 bExit.setFont(new java.awt.Font("MS Sans Serif", 0, 10));
504 bExit.setText("x");
505 bExit.setToolTipText("Exit");
506 bExit.setBorderPainted(false);
507 bExit.setFocusPainted(false);
508 bExit.setMargin(new java.awt.Insets(0, 0, 0, 0));
509 bExit.setMaximumSize(new java.awt.Dimension(13, 11));
510 bExit.setMinimumSize(new java.awt.Dimension(13, 11));
511 bExit.setPreferredSize(new java.awt.Dimension(13, 11));
512 bExit.addActionListener(new java.awt.event.ActionListener() {
513 public void actionPerformed(java.awt.event.ActionEvent evt) {
514 bExitActionPerformed(evt);
515 }
516 });
517
518 jToolBar1.add(bExit);
519
520 buttonGroup1.add(jRadioButton1);
521 jRadioButton1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
522 jRadioButton1.setMargin(new java.awt.Insets(0, 0, 0, 0));
523 jToolBar1.add(jRadioButton1);
524
525 bMenuButton.setFont(new java.awt.Font("Microsoft Sans Serif", 0, 10));
526 bMenuButton.setText("o");
527 bMenuButton.setToolTipText("\u041c\u0435\u043d\u044e");
528 bMenuButton.setBorderPainted(false);
529 bMenuButton.setFocusPainted(false);
530 bMenuButton.setMargin(new java.awt.Insets(0, 0, 0, 0));
531 bMenuButton.setMaximumSize(new java.awt.Dimension(13, 11));
532 bMenuButton.setMinimumSize(new java.awt.Dimension(13, 11));
533 bMenuButton.setPreferredSize(new java.awt.Dimension(13, 11));
534 bMenuButton.addActionListener(new java.awt.event.ActionListener() {
535 public void actionPerformed(java.awt.event.ActionEvent evt) {
536 bMenuButtonActionPerformed(evt);
537 }
538 });
539
540 jToolBar1.add(bMenuButton);
541
542 org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
543 getContentPane().setLayout(layout);
544 layout.setHorizontalGroup(
545 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
546 .add(layout.createSequentialGroup()
547 .addContainerGap()
548 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
549 .add(org.jdesktop.layout.GroupLayout.LEADING, LCDPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
550 .add(org.jdesktop.layout.GroupLayout.LEADING, LEDS, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
551 .add(org.jdesktop.layout.GroupLayout.LEADING, buttons, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
552 .addContainerGap(11, Short.MAX_VALUE))
553 .add(jToolBar1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 239, Short.MAX_VALUE)
554 );
555 layout.setVerticalGroup(
556 layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
557 .add(layout.createSequentialGroup()
558 .addContainerGap()
559 .add(LCDPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
560 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
561 .add(LEDS, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 34, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
562 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
563 .add(buttons, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
564 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
565 .add(jToolBar1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
566 );
567 pack();
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 private void bKorenActionPerformed(java.awt.event.ActionEvent evt) {
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614 char firstChar = LCD.getText().charAt(0);
615
616
617
618
619
620
621
622
623
624
625
626
627 if(firstChar != '-') {
628
629
630
631
632
633
634
635
636
637
638
639
640 double displayed = Double.parseDouble(LCD.getText());
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658 LCD.setText(Double.toString(Math.sqrt(displayed)));
659
660
661
662 isSigned = true;
663 }
664 }
665
666
667
668 private void bKubActionPerformed(java.awt.event.ActionEvent evt) {
669
670
671
672
673 String displayed = LCD.getText();
674 double dDisplayed = Double.parseDouble(displayed);
675
676
677
678
679 double result = dDisplayed * dDisplayed * dDisplayed;
680
681
682
683 LCD.setText(Double.toString(result));
684
685
686
687 isSigned = true;
688 }
689
690
691
692 private void bKvadratActionPerformed(java.awt.event.ActionEvent evt) {
693 String displayed = LCD.getText();
694 double dDisplayed = Double.parseDouble(displayed);
695 double result = dDisplayed * dDisplayed;
696 LCD.setText(Double.toString(result));
697 isSigned = true;
698 }
699
700
701
702 private void bSignActionPerformed(java.awt.event.ActionEvent evt) {
703
704
705 String displayed = LCD.getText();
706
707
708
709 char firstChar = displayed.charAt(0);
710
711 if(firstChar == '-') {
712
713
714
715
716
717
718
719
720 LCD.setText(displayed.substring(1));
721
722 } else {
723
724
725
726
727
728
729 LCD.setText('-' + displayed);
730 }
731 }
732
733
734
735 private void bDeleteActionPerformed(java.awt.event.ActionEvent evt) {
736
737
738
739
740
741
742
743
744 if(LCD.getText().length() != 1) {
745
746
747
748
749
750
751
752
753
754
755 LCD.setText(LCD.getText().substring(0, LCD.getText().length() - 1));
756
757
758 } else {
759 LCD.setText("0");
760 }
761
762
763
764
765
766 }
767
768
769
770
771
772
773 private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
774
775
776
777
778
779
780
781
782
783
784 About ab = new About(this, true);
785
786
787
788 ab.setVisible(true);
789 }
790
791
792
793 private void bExitActionPerformed(java.awt.event.ActionEvent evt) {
794
795 setVisible(false);
796
797
798 dispose();
799
800
801 System.exit(0);
802 }
803
804 private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {
805 setVisible(false);
806 dispose();
807 System.exit(0);
808 }
809
810
811
812 private void bMenuButtonActionPerformed(java.awt.event.ActionEvent evt) {
813
814
815
816
817
818
819
820 popup.show(bMenuButton, 5, 5);
821 }
822
823
824
825
826
827 private void bResetActionPerformed(java.awt.event.ActionEvent evt) {
828 LCD.setText("0");
829 sign = ' ';
830 isSigned = true;
831 val = 0;
832 isDotted = false;
833 jRadioButton1.setVisible(false);
834 jRadioButton1.setSelected(true);
835 }
836
837
838
839
840 private void bMultipleActionPerformed(java.awt.event.ActionEvent evt) {
841 rbMultip.setSelected(true);
842 signPressed('*');
843 }
844
845
846
847
848
849 private void bDrobActionPerformed(java.awt.event.ActionEvent evt) {
850 rbDrob.setSelected(true);
851 signPressed('/');
852 }
853
854
855
856
857
858 private void bMinusActionPerformed(java.awt.event.ActionEvent evt) {
859 rbMinus.setSelected(true);
860 signPressed('-');
861 }
862
863
864
865
866
867 private void bPlusActPerf(java.awt.event.ActionEvent evt) {
868 rbPlus.setSelected(true);
869 signPressed('+');
870 }
871
872 private void bEqualActPerf(java.awt.event.ActionEvent evt) {
873
874 double result = 0;
875
876
877
878
879
880
881
882 double second = new Double(LCD.getText()).doubleValue();
883
884
885
886
887
888
889
890
891
892
893
894
895 switch(sign) {
896 case '+':
897 result = val + second; break;
898 case '-':
899 result = val - second; break;
900 case '*':
901 result = val * second; break;
902 case '/':
903 result = val / second; break;
904 case ' ':
905 result = val + second; break;
906 }
907
908
909
910 LCD.setText(Double.toString(result));
911
912 sign = ' ';
913 isSigned = true;
914 val = 0;
915 isDotted = false;
916
917
918
919
920
921
922
923
924
925 jRadioButton1.setSelected(true);
926 }
927
928
929
930
931
932 private void b0ActPerf(java.awt.event.ActionEvent evt) {
933 digitPressed(0);
934 }
935
936
937 private void bDotActPerf(java.awt.event.ActionEvent evt) {
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953 if(isSigned) {
954
955
956 LCD.setText("0.");
957
958 isDotted = true;
959 isSigned = false;
960
961 } else {
962
963
964
965
966
967
968
969 if(!isDotted) {
970
971 LCD.setText(LCD.getText() + ".");
972
973
974 isDotted = true;
975
976 isSigned = false;
977 }
978 }
979
980
981
982
983
984
985
986
987
988 }
989
990 private void b9ActPerf(java.awt.event.ActionEvent evt) {
991 digitPressed(9);
992 }
993
994 private void b8ActPerf(java.awt.event.ActionEvent evt) {
995 digitPressed(8);
996 }
997
998 private void b7ActPerf(java.awt.event.ActionEvent evt) {
999 digitPressed(7);
1000 }
1001
1002 private void b6ActPerf(java.awt.event.ActionEvent evt) {
1003 digitPressed(6);
1004 }
1005
1006 private void b5ActPerf(java.awt.event.ActionEvent evt) {
1007 digitPressed(5);
1008 }
1009
1010 private void b4ActPerf(java.awt.event.ActionEvent evt) {
1011 digitPressed(4);
1012 }
1013
1014 private void b3ActPerf(java.awt.event.ActionEvent evt) {
1015 digitPressed(3);
1016 }
1017
1018 private void b2ActPerf(java.awt.event.ActionEvent evt) {
1019 digitPressed(2);
1020 }
1021
1022 private void b1ActPerf(java.awt.event.ActionEvent evt) {
1023 digitPressed(1);
1024 }
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036 public static void main(String args[]) {
1037 java.awt.EventQueue.invokeLater(new Runnable() {
1038 public void run() {
1039 new Calculator().setVisible(true);
1040 }
1041 });
1042 }
1043
1044
1045
1046
1047
1048 private boolean isSigned = true;
1049 private boolean isDotted = false;
1050
1051
1052
1053 private char sign = ' ';
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065 private double val = 0;
1066
1067
1068
1069
1070 private void signPressed(char _sign) {
1071
1072 double result = 0;
1073
1074 double second = new Double(LCD.getText()).doubleValue();
1075
1076 switch(sign) {
1077 case '+':
1078 result = val + second; break;
1079 case '-':
1080 result = val - second; break;
1081 case '*':
1082 result = val * second; break;
1083 case '/':
1084 result = val / second; break;
1085 case ' ':
1086 result = val + second; break;
1087 }
1088
1089 val = result;
1090
1091
1092 LCD.setText(Double.toString(result));
1093
1094
1095 sign = _sign;
1096
1097 isSigned = true;
1098 isDotted = false;
1099 }
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110 private void digitPressed(int _digit) {
1111
1112 if(_digit == 0) {
1113
1114
1115
1116
1117 if(!LCD.getText().equals("0")) {
1118
1119
1120 if(isSigned) {
1121
1122
1123
1124
1125
1126 LCD.setText(Integer.toString(_digit));
1127
1128
1129 } else {
1130
1131
1132
1133
1134
1135 LCD.setText(LCD.getText() + Integer.toString(_digit));
1136 }
1137
1138 } else {
1139
1140 LCD.setText("0");
1141
1142 isSigned = false;
1143 }
1144
1145 } else {
1146
1147
1148 if(isSigned) {
1149
1150
1151 LCD.setText(Integer.toString(_digit));
1152
1153 isSigned = false;
1154
1155
1156 } else {
1157
1158 if(!LCD.getText().equals("0")) {
1159
1160 LCD.setText(LCD.getText() + Integer.toString(_digit));
1161
1162 } else {
1163
1164 LCD.setText(Integer.toString(_digit));
1165 }
1166 }
1167 }
1168 }
1169
1170
1171 private javax.swing.JTextField LCD;
1172 private javax.swing.JPanel LCDPanel;
1173 private javax.swing.JPanel LEDS;
1174 private javax.swing.JButton b0;
1175 private javax.swing.JButton b1;
1176 private javax.swing.JButton b2;
1177 private javax.swing.JButton b3;
1178 private javax.swing.JButton b4;
1179 private javax.swing.JButton b5;
1180 private javax.swing.JButton b6;
1181 private javax.swing.JButton b7;
1182 private javax.swing.JButton b8;
1183 private javax.swing.JButton b9;
1184 private javax.swing.JButton bDelete;
1185 private javax.swing.JButton bDot;
1186 private javax.swing.JButton bDrob;
1187 private javax.swing.JButton bEqual;
1188 private javax.swing.JButton bExit;
1189 private javax.swing.JButton bKoren;
1190 private javax.swing.JButton bKub;
1191 private javax.swing.JButton bKvadrat;
1192 private javax.swing.JButton bMenuButton;
1193 private javax.swing.JButton bMinus;
1194 private javax.swing.JButton bMultiple;
1195 private javax.swing.JButton bPlus;
1196 private javax.swing.JButton bReset;
1197 private javax.swing.JButton bSign;
1198 private javax.swing.ButtonGroup buttonGroup1;
1199 private javax.swing.JPanel buttons;
1200 private javax.swing.JLabel jLabel1;
1201 private javax.swing.JLabel jLabel2;
1202 private javax.swing.JLabel jLabel3;
1203 private javax.swing.JLabel jLabel4;
1204 private javax.swing.JMenuItem jMenuItem2;
1205 private javax.swing.JMenuItem jMenuItem3;
1206 private javax.swing.JRadioButton jRadioButton1;
1207 private javax.swing.JToolBar jToolBar1;
1208 private javax.swing.JPopupMenu popup;
1209 private javax.swing.JRadioButton rbDrob;
1210 private javax.swing.JRadioButton rbMinus;
1211 private javax.swing.JRadioButton rbMultip;
1212 private javax.swing.JRadioButton rbPlus;
1213
1214
1215 }
1216