My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions

Issue 1 attachment: VistaCalculadora.java (19.0 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
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
/*
* VistaCalculadora.java
*
* Created on 5 de noviembre de 2008, 10:07 AM
*/

package Calculador.Vista;

import Calculador.Modelo.Calculadora;

/**
*
* @author user
*/
public class VistaCalculadora extends javax.swing.JFrame {

/** Creates new form VistaCalculadora */
public VistaCalculadora() {
calcu=new Calculadora();
initComponents();
}

/** 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.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

jPanel1 = new javax.swing.JPanel();
btn_1 = new javax.swing.JButton();
btn_2 = new javax.swing.JButton();
btn_3 = new javax.swing.JButton();
btn_CE = new javax.swing.JButton();
btn_CL = new javax.swing.JButton();
btn_4 = new javax.swing.JButton();
btn_5 = new javax.swing.JButton();
btn_6 = new javax.swing.JButton();
btn_M = new javax.swing.JButton();
btn_r = new javax.swing.JButton();
btn_7 = new javax.swing.JButton();
btn_8 = new javax.swing.JButton();
btn_9 = new javax.swing.JButton();
btn_suma = new javax.swing.JButton();
btn_restar = new javax.swing.JButton();
btn_punto = new javax.swing.JButton();
btn_0 = new javax.swing.JButton();
btn_mult = new javax.swing.JButton();
btn_divid = new javax.swing.JButton();
btn_igual = new javax.swing.JButton();
btn_pi = new javax.swing.JButton();
btn_memoria = new javax.swing.JButton();
texto = new javax.swing.JTextField();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Calculadora");

jPanel1.setLayout(new java.awt.GridLayout(5, 5, 2, 2));

btn_1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
btn_1.setText("1");
btn_1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btn_1MouseClicked(evt);
}
});
jPanel1.add(btn_1);

btn_2.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
btn_2.setText("2");
btn_2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btn_2MouseClicked(evt);
}
});
jPanel1.add(btn_2);

btn_3.setFont(new java.awt.Font("Tahoma", 1, 18));
btn_3.setText("3");
btn_3.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btn_3MouseClicked(evt);
}
});
btn_3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_3ActionPerformed(evt);
}
});
jPanel1.add(btn_3);

btn_CE.setFont(new java.awt.Font("Tahoma", 1, 12));
btn_CE.setText("CE");
btn_CE.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btn_CEMouseClicked(evt);
}
});
btn_CE.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_CEActionPerformed(evt);
}
});
jPanel1.add(btn_CE);

btn_CL.setFont(new java.awt.Font("Tahoma", 1, 14));
btn_CL.setText("CL");
btn_CL.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btn_CLMouseClicked(evt);
}
});
jPanel1.add(btn_CL);

btn_4.setFont(new java.awt.Font("Tahoma", 1, 18));
btn_4.setText("4");
btn_4.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btn_4MouseClicked(evt);
}
});
btn_4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_4ActionPerformed(evt);
}
});
jPanel1.add(btn_4);

btn_5.setFont(new java.awt.Font("Tahoma", 1, 18));
btn_5.setText("5");
btn_5.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btn_5MouseClicked(evt);
}
});
jPanel1.add(btn_5);

btn_6.setFont(new java.awt.Font("Tahoma", 1, 18));
btn_6.setText("6");
btn_6.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btn_6MouseClicked(evt);
}
});
jPanel1.add(btn_6);

btn_M.setFont(new java.awt.Font("Tahoma", 1, 18));
btn_M.setText("M");
btn_M.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btn_MMouseClicked(evt);
}
});
jPanel1.add(btn_M);

btn_r.setFont(new java.awt.Font("Tahoma", 1, 18));
btn_r.setText("r");
btn_r.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btn_rMouseClicked(evt);
}
});
jPanel1.add(btn_r);

btn_7.setFont(new java.awt.Font("Tahoma", 1, 18));
btn_7.setText("7");
btn_7.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btn_7MouseClicked(evt);
}
});
jPanel1.add(btn_7);

btn_8.setFont(new java.awt.Font("Tahoma", 1, 18));
btn_8.setText("8");
btn_8.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btn_8MouseClicked(evt);
}
});
jPanel1.add(btn_8);

btn_9.setFont(new java.awt.Font("Tahoma", 1, 18));
btn_9.setText("9");
btn_9.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btn_9MouseClicked(evt);
}
});
jPanel1.add(btn_9);

btn_suma.setFont(new java.awt.Font("Tahoma", 1, 18));
btn_suma.setText("+");
btn_suma.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btn_sumaMouseClicked(evt);
}
});
jPanel1.add(btn_suma);

btn_restar.setFont(new java.awt.Font("Tahoma", 1, 18));
btn_restar.setText("-");
btn_restar.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btn_restarMouseClicked(evt);
}
});
jPanel1.add(btn_restar);

btn_punto.setFont(new java.awt.Font("Tahoma", 1, 18));
btn_punto.setText(".");
btn_punto.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btn_puntoMouseClicked(evt);
}
});
jPanel1.add(btn_punto);

btn_0.setFont(new java.awt.Font("Tahoma", 1, 18));
btn_0.setText("0");
btn_0.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btn_0MouseClicked(evt);
}
});
jPanel1.add(btn_0);

btn_mult.setFont(new java.awt.Font("Tahoma", 1, 18));
btn_mult.setText("*");
btn_mult.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btn_multMouseClicked(evt);
}
});
jPanel1.add(btn_mult);

btn_divid.setFont(new java.awt.Font("Tahoma", 1, 18));
btn_divid.setText("/");
btn_divid.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btn_dividMouseClicked(evt);
}
});
jPanel1.add(btn_divid);

btn_igual.setFont(new java.awt.Font("Tahoma", 1, 18));
btn_igual.setText("=");
btn_igual.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btn_igualMouseClicked(evt);
}
});
btn_igual.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btn_igualActionPerformed(evt);
}
});
jPanel1.add(btn_igual);

btn_pi.setFont(new java.awt.Font("Tahoma", 1, 18));
btn_pi.setText("p");
btn_pi.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btn_piMouseClicked(evt);
}
});
jPanel1.add(btn_pi);

btn_memoria.setFont(new java.awt.Font("Tahoma", 0, 10));
btn_memoria.setText("M+");
btn_memoria.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
btn_memoriaMouseClicked(evt);
}
});
jPanel1.add(btn_memoria);

texto.setFont(new java.awt.Font("Arial", 1, 14));

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(40, 40, 40)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 270, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(texto, javax.swing.GroupLayout.PREFERRED_SIZE, 270, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(90, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(42, 42, 42)
.addComponent(texto, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(44, 44, 44))
);

pack();
}// </editor-fold>//GEN-END:initComponents

private void btn_1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_1MouseClicked
texto.setText(texto.getText()+btn_1.getText());
}//GEN-LAST:event_btn_1MouseClicked

private void btn_2MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_2MouseClicked
texto.setText(texto.getText()+btn_2.getText());
}//GEN-LAST:event_btn_2MouseClicked

private void btn_3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_3MouseClicked
texto.setText(texto.getText()+btn_3.getText());
}//GEN-LAST:event_btn_3MouseClicked

private void btn_4MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_4MouseClicked
texto.setText(texto.getText()+btn_4.getText());
}//GEN-LAST:event_btn_4MouseClicked

private void btn_5MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_5MouseClicked
texto.setText(texto.getText()+btn_5.getText());
}//GEN-LAST:event_btn_5MouseClicked

private void btn_7MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_7MouseClicked
texto.setText(texto.getText()+btn_7.getText());
}//GEN-LAST:event_btn_7MouseClicked

private void btn_8MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_8MouseClicked
texto.setText(texto.getText()+btn_8.getText());
}//GEN-LAST:event_btn_8MouseClicked

private void btn_9MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_9MouseClicked
texto.setText(texto.getText()+btn_9.getText());
}//GEN-LAST:event_btn_9MouseClicked

private void btn_6MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_6MouseClicked
texto.setText(texto.getText()+btn_6.getText());
}//GEN-LAST:event_btn_6MouseClicked

private void btn_0MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_0MouseClicked
texto.setText(texto.getText()+btn_0.getText());
}//GEN-LAST:event_btn_0MouseClicked

private void btn_puntoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_puntoMouseClicked
texto.setText(texto.getText()+btn_punto.getText());
}//GEN-LAST:event_btn_puntoMouseClicked

private void btn_igualActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_igualActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_btn_igualActionPerformed

private void btn_sumaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_sumaMouseClicked
calcu.setNum1(Double.parseDouble(texto.getText()));
calcu.setOperacion(btn_suma.getText());
texto.setText("");
}//GEN-LAST:event_btn_sumaMouseClicked

private void btn_igualMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_igualMouseClicked
calcu.setNum2(Double.parseDouble(texto.getText()));
if(calcu.getOperacion().equals("+")){
texto.setText( ""+calcu.sumar(calcu.getNum1(), calcu.getNum2()));
}else{
if(calcu.getOperacion()=="-"){
texto.setText( ""+calcu.restar(calcu.getNum1(), calcu.getNum2()));
}else{
if(calcu.getOperacion()=="*"){
texto.setText( ""+calcu.multiplicar(calcu.getNum1(), calcu.getNum2()));
}else{
if(calcu.getOperacion()=="/"){
texto.setText( ""+calcu.dividir(calcu.getNum1(), calcu.getNum2()));
}else{
if(calcu.getOperacion()=="r"){
texto.setText(""+calcu.raiz(calcu.getResp()));
}
}
}
}
}
}//GEN-LAST:event_btn_igualMouseClicked

private void btn_restarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_restarMouseClicked
calcu.setNum1(Double.parseDouble(texto.getText()));
calcu.setOperacion(btn_restar.getText());
texto.setText("");

}//GEN-LAST:event_btn_restarMouseClicked

private void btn_multMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_multMouseClicked
calcu.setNum1(Double.parseDouble(texto.getText()));
calcu.setOperacion(btn_mult.getText());
texto.setText("");

}//GEN-LAST:event_btn_multMouseClicked

private void btn_dividMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_dividMouseClicked
calcu.setNum1(Double.parseDouble(texto.getText()));
calcu.setOperacion(btn_divid.getText());
texto.setText("");

}//GEN-LAST:event_btn_dividMouseClicked

private void btn_CEMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_CEMouseClicked
texto.setText("");
}//GEN-LAST:event_btn_CEMouseClicked

private void btn_CLMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_CLMouseClicked
texto.setText("");
calcu.setOperacion("");
calcu.setMemoria(0.0);
calcu.setNum1(0.0);
calcu.setNum2(0.0);
}//GEN-LAST:event_btn_CLMouseClicked

private void btn_rMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_rMouseClicked
calcu.setNum1(Double.parseDouble(texto.getText()));
texto.setText( ""+calcu.raiz(calcu.getNum1()));

}//GEN-LAST:event_btn_rMouseClicked

private void btn_piMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_piMouseClicked
texto.setText(""+Math.PI);
}//GEN-LAST:event_btn_piMouseClicked

private void btn_CEActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_CEActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_btn_CEActionPerformed

private void btn_MMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_MMouseClicked
calcu.setMemoria(calcu.getResp());
}//GEN-LAST:event_btn_MMouseClicked

private void btn_memoriaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btn_memoriaMouseClicked
texto.setText(""+calcu.getMemoria());
}//GEN-LAST:event_btn_memoriaMouseClicked

private void btn_3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_3ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_btn_3ActionPerformed

private void btn_4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_4ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_btn_4ActionPerformed

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new VistaCalculadora().setVisible(true);
}
});
}

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btn_0;
private javax.swing.JButton btn_1;
private javax.swing.JButton btn_2;
private javax.swing.JButton btn_3;
private javax.swing.JButton btn_4;
private javax.swing.JButton btn_5;
private javax.swing.JButton btn_6;
private javax.swing.JButton btn_7;
private javax.swing.JButton btn_8;
private javax.swing.JButton btn_9;
private javax.swing.JButton btn_CE;
private javax.swing.JButton btn_CL;
private javax.swing.JButton btn_M;
private javax.swing.JButton btn_divid;
private javax.swing.JButton btn_igual;
private javax.swing.JButton btn_memoria;
private javax.swing.JButton btn_mult;
private javax.swing.JButton btn_pi;
private javax.swing.JButton btn_punto;
private javax.swing.JButton btn_r;
private javax.swing.JButton btn_restar;
private javax.swing.JButton btn_suma;
private javax.swing.JPanel jPanel1;
private javax.swing.JTextField texto;
// End of variables declaration//GEN-END:variables
private Calculador.Modelo.Calculadora calcu;
}
Powered by Google Project Hosting