Está en la página 1de 4

package calculadora; * */ publicclassInterFazCalculadoraextendsjavax.swing.

JFrame { doublemasmenos; doubleprimerdouble; doublesegundouble; doubletotaldouble; //para los botones intmasClic; intmenosClic; intdivClic; intmultiClic; intdecimalClic; /** Creates new form InterFazCalculadora */ publicInterFazCalculadora() { initComponents(); } ESTE METODO SERIA IGUAL PARA CADA UNO DE LOS BOTONES DE NUMERO private void btnCincoActionPerformed(java.awt.event.ActionEventevt) { // TODO add your handling code here: txtDisplay.setText(txtDisplay.getText()+btnCinco.getText()); } METODO PARA EL BOTON DE LIMPIAR private void btnLimpiaActionPerformed(java.awt.event.ActionEventevt) { // TODO add your handling code here: txtDisplay.setText(""); decimalClic=0; } METODO PARA EL BOTON DE PUNTO private void btnPuntoActionPerformed(java.awt.event.ActionEventevt) { // TODO add your handling code here: if(decimalClic==0){ txtDisplay.setText(txtDisplay.getText()+btnPunto.getText()); } decimalClic=1; }

METODO PARA EL BOTON DE MAS-MENOS private void btnMasMenosActionPerformed(java.awt.event.ActionEventevt) { // TODO add your handling code here: masmenos=(Double.parseDouble(String.valueOf(txtDisplay.getText()))); masmenos=masmenos*(-1); txtDisplay.setText(String.valueOf(masmenos)); } METODO PARA EL BOTON DE MAS private void btnMasActionPerformed(java.awt.event.ActionEventevt) { // TODO add your handling code here: primerdouble=(Double.parseDouble(String.valueOf(txtDisplay.getText()))); txtDisplay.setText(""); masClic=1; decimalClic=0; } METODO PARA EL BOTON MENOS Y REPITEN PARA LOS BOTONES DE MULTIMPLICACION Y DIVISION, SOLO HAY Q CAMBBIAR LAS VARIABLES CORRESPONDIENTES private void btnMenosActionPerformed(java.awt.event.ActionEventevt) { // TODO add your handling code here: primerdouble=(Double.parseDouble(String.valueOf(txtDisplay.getText()))); txtDisplay.setText(""); menosClic=1; decimalClic=0; METODO PARA EL BOTON DE IGUAL private void btnIgualActionPerformed(java.awt.event.ActionEventevt) { // TODO add your handling code here: segundouble=(Double.parseDouble(String.valueOf(txtDisplay.getText()))); if(masClic>0){ totaldouble=primerdouble+segundouble; txtDisplay.setText(String.valueOf(totaldouble)); primerdouble=0; segundouble=0; masClic=0; } if(menosClic>0){ totaldouble=primerdouble-segundouble; txtDisplay.setText(String.valueOf(totaldouble)); primerdouble=0;

segundouble=0; menosClic=0; } if(multiClic>0){ totaldouble=primerdouble*segundouble; txtDisplay.setText(String.valueOf(totaldouble)); primerdouble=0; segundouble=0; multiClic=0; } if(divClic>0){ totaldouble=primerdouble/segundouble; txtDisplay.setText(String.valueOf(totaldouble)); primerdouble=0; segundouble=0; divClic=0; } } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { newInterFazCalculadora().setVisible(true); } }); } // Variables declaration - do not modify privatejavax.swing.JButtonbtnCero; privatejavax.swing.JButtonbtnCinco; privatejavax.swing.JButtonbtnCuatro; privatejavax.swing.JButtonbtnDivide; privatejavax.swing.JButtonbtnDos; privatejavax.swing.JButtonbtnIgual; privatejavax.swing.JButtonbtnLimpia; privatejavax.swing.JButtonbtnMas; privatejavax.swing.JButtonbtnMasMenos; privatejavax.swing.JButtonbtnMenos; privatejavax.swing.JButtonbtnMultiplica; privatejavax.swing.JButtonbtnNueve; privatejavax.swing.JButtonbtnOcho; privatejavax.swing.JButtonbtnPunto; privatejavax.swing.JButtonbtnSeis; privatejavax.swing.JButtonbtnSiete; privatejavax.swing.JButtonbtnTres; privatejavax.swing.JButtonbtnUno;

privatejavax.swing.JLabeltxtDisplay; // End of variables declaration

También podría gustarte