Foros del Web » Programación para mayores de 30 ;) » Java »

Problemas con calculadora

Estas en el tema de Problemas con calculadora en el foro de Java en Foros del Web. Cordial saludo Amigos necesito ayuda para programar los eventos de los botones de (.) que al presionarlo se muestra en pantalla por ejemplo 2.2 y ...
  #1 (permalink)  
Antiguo 14/11/2012, 11:29
Avatar de afal3d  
Fecha de Ingreso: octubre-2012
Mensajes: 24
Antigüedad: 11 años, 6 meses
Puntos: 0
Información Problemas con calculadora

Cordial saludo
Amigos necesito ayuda para programar los eventos de los botones de (.) que al presionarlo se muestra en pantalla por ejemplo 2.2 y al sumarlo, restarlo...etc. con otro numero y presionar el botón igual me de un resultado, el otro botón es el CE para que al presionarlo me guarde la operación que se lleva y poder seguir trabajando.

He buscado ayuda en diferentes foros de otras paginas y nadie me colabora le agradecería si lo hacen ya que tengo esta inquietud y me gustaría seguir avanzando con este proyecto en netbeans 7.2.

Código:
package AppletCalculadora_GUI;

/**
 *
 * @author JAAM3D
 */
public class AppletCalculadora_GUI_SENA extends javax.swing.JApplet {
    String Numero="";
 int valor=0;
    int signo=0;
    int memoria=0;
   
private void btn1ActionPerformed(java.awt.event.ActionEvent evt) {                                     
Numero += 1;
Numero1.setText(Numero);// TODO add your handling code here:
    }                                    

    private void btn2ActionPerformed(java.awt.event.ActionEvent evt) {                                     
Numero += 2;
Numero1.setText(Numero);  // TODO add your handling code here:
    }                                    

    private void btn3ActionPerformed(java.awt.event.ActionEvent evt) {                                     
Numero += 3;
Numero1.setText(Numero);        // TODO add your handling code here:
    }                                    

    private void btn4ActionPerformed(java.awt.event.ActionEvent evt) {                                     
Numero += 4;
Numero1.setText(Numero);        // TODO add your handling code here:
    }                                    

    private void btn5ActionPerformed(java.awt.event.ActionEvent evt) {                                     
Numero += 5;
Numero1.setText(Numero);        // TODO add your handling code here:
    }                                    

    private void btn6ActionPerformed(java.awt.event.ActionEvent evt) {                                     
Numero += 6;
Numero1.setText(Numero);        // TODO add your handling code here:
    }                                    

    private void btn7ActionPerformed(java.awt.event.ActionEvent evt) {                                     
Numero += 7;
Numero1.setText(Numero);        // TODO add your handling code here:
    }                                    

    private void btn8ActionPerformed(java.awt.event.ActionEvent evt) {                                     
Numero += 8;
Numero1.setText(Numero);        // TODO add your handling code here:
    }                                    

    private void btn9ActionPerformed(java.awt.event.ActionEvent evt) {                                     
Numero += 9;
Numero1.setText(Numero);        // TODO add your handling code here:
    }                                    

    private void btn0ActionPerformed(java.awt.event.ActionEvent evt) {                                     
Numero += 0;
Numero1.setText(Numero);        // TODO add your handling code here:
    }                                    

    private void btnCEActionPerformed(java.awt.event.ActionEvent evt) {                                      
       // TODO add your handling code here:
    }                                     

    private void btnSumaActionPerformed(java.awt.event.ActionEvent evt) {                                        
valor=Integer.parseInt(Numero);
Numero1.setText("0");
signo=1;
Numero1.setText("");
Numero="";
// TODO add your handling code here:
    }                                       

    private void btnRestaActionPerformed(java.awt.event.ActionEvent evt) {                                         
valor=Integer.parseInt(Numero);
Numero1.setText("0");
signo=2;
Numero1.setText("");
Numero="";        // TODO add your handling code here:
    }                                        

    private void btnIgualActionPerformed(java.awt.event.ActionEvent evt) {                                         
if(signo==1){
    valor += Integer.parseInt(Numero);
    Numero1.setText(Integer.toString(valor));
    }
if(signo==2){
    valor -= Integer.parseInt(Numero);
    Numero1.setText(Integer.toString(valor));
    }
if(signo==3){
    valor *= Integer.parseInt(Numero);
    Numero1.setText(Integer.toString(valor));
    }
if(signo==4){
    valor /= Integer.parseInt(Numero);
    Numero1.setText(Integer.toString(valor));
    }

Numero="";
    // TODO add your handling code here:
    }                                        

    private void btnMultiplicacionActionPerformed(java.awt.event.ActionEvent evt) {                                                  
valor=Integer.parseInt(Numero);
Numero1.setText("0");
signo=3;
Numero1.setText("");
Numero="";        // TODO add your handling code here:
    }                                                 

    private void btnDivicionActionPerformed(java.awt.event.ActionEvent evt) {                                            
valor=Integer.parseInt(Numero);
Numero1.setText("0");
signo=4;
Numero1.setText("");
Numero="";     // TODO add your handling code here:
    }                                           

    private void btnCActionPerformed(java.awt.event.ActionEvent evt) {                                     
Numero1.setText("");        // TODO add your handling code here:
    }                                    

    private void btnSalirActionPerformed(java.awt.event.ActionEvent evt) {                                         
    System.exit(0);    // TODO add your handling code here:
    }                                        

    private void btnPuntoActionPerformed(java.awt.event.ActionEvent evt) {                                         
Numero=Numero.concat(".");
Numero1.setText(Numero);
    	      
// TODO add your handling code here:
    }                                        

    // Variables declaration - do not modify                     
    private javax.swing.JTextField Numero1;
    private javax.swing.JButton btn0;
    private javax.swing.JButton btn1;
    private javax.swing.JButton btn2;
    private javax.swing.JButton btn3;
    private javax.swing.JButton btn4;
    private javax.swing.JButton btn5;
    private javax.swing.JButton btn6;
    private javax.swing.JButton btn7;
    private javax.swing.JButton btn8;
    private javax.swing.JButton btn9;
    private javax.swing.JButton btnC;
    private javax.swing.JButton btnCE;
    private javax.swing.JButton btnDivicion;
    private javax.swing.JButton btnIgual;
    private javax.swing.JButton btnMultiplicacion;
    private javax.swing.JButton btnPunto;
    private javax.swing.JButton btnResta;
    private javax.swing.JButton btnSalir;
    private javax.swing.JButton btnSuma;
    // End of variables declaration                   

   

   
}

Link de descarga delo que he trabajado hasta ahora.

http://www.4shared.com/rar/SLgv4pnt/AppletCalculadora_2.html
  #2 (permalink)  
Antiguo 15/11/2012, 09:32
Avatar de ARICARRARO  
Fecha de Ingreso: diciembre-2010
Ubicación: México
Mensajes: 227
Antigüedad: 13 años, 4 meses
Puntos: 10
Respuesta: Problemas con calculadora

Aqui hay muchos ejempos de Applets: http://java-elrincondetucasa.blogspot.mx

Última edición por ARICARRARO; 15/11/2012 a las 09:34 Razón: link
  #3 (permalink)  
Antiguo 15/11/2012, 10:33
Avatar de afal3d  
Fecha de Ingreso: octubre-2012
Mensajes: 24
Antigüedad: 11 años, 6 meses
Puntos: 0
Respuesta: Problemas con calculadora

Amigo lo que yo necesito saber es cual es el error que estoy cometiendo al programar los botosnes de (.) y (MC) ya que al programarlos y precionar el boton igual me marcan error.
soy nuevo en esto de programar en java y en la red ya encuentro calculadoras echas y con otro tipo de codificacion...pero esta la realice desde cero en base a consultas y me gustaria terminarla y aprender un poco mas del error que estoy cometiendo y saber como se hace de la manera correcta.
ya rebise el link y solo encontre proyectos un poco mas avanzados y todavia no he llegado hasta alla con el tiempo desde luego que le sacare provecho por eso la agregue a favoritos.

Etiquetas: calculadora, netbeans, programa, string
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 09:48.