0% found this document useful (0 votes)
43 views4 pages

Practica1 PDF

This document contains code for a calculator application created in Java Swing. It includes code for: 1) Variables to track the state of calculator buttons like addition and decimal points. 2) Methods for each number button that update the display text with the button value. 3) Methods for operations buttons like addition, subtraction, etc that parse the display to double, perform the operation, and update the display with the result.

Uploaded by

bernardo10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views4 pages

Practica1 PDF

This document contains code for a calculator application created in Java Swing. It includes code for: 1) Variables to track the state of calculator buttons like addition and decimal points. 2) Methods for each number button that update the display text with the button value. 3) Methods for operations buttons like addition, subtraction, etc that parse the display to double, perform the operation, and update the display with the result.

Uploaded by

bernardo10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

ISTP: Manuel Seoane Corrales Java Swing  

CALCULADORA CON JAVA EN NETBEANS      int menosClic; 
      int divClic; 
      int multiClic; 
      int decimalClic; 
   
  private void btnLimpiarActionPerformed(java.awt.event.ActionEvent evt) 
  {                                            
          // TODO add your handling code here: 
          txtDisplay.setText(""); 
          decimalClic=0; 
      }                                           
   
      private void btnUnoActionPerformed(java.awt.event.ActionEvent evt) {                               
          // TODO add your handling code here: 
          txtDisplay.setText(txtDisplay.getText()+btnUno.getText()); 
  }                                       
   
      private void btnDosActionPerformed(java.awt.event.ActionEvent evt) {                               
         txtDisplay.setText(txtDisplay.getText()+btnDos.getText()); 
      }                                       
   
      private void btnTresActionPerformed(java.awt.event.ActionEvent evt) {                               
          // TODO add your handling code here: 
public class Calculadora extends javax.swing.JFrame {          txtDisplay.setText(txtDisplay.getText()+btnTres.getText()); 
//variables      }                                        
    double masmenos;   
    double primerdouble;      private void btnCuatroActionPerformed(java.awt.event.ActionEvent 
    double segundouble;  evt) {                                           
    double totaldouble;          // TODO add your handling code here: 
    //para los botones          txtDisplay.setText(txtDisplay.getText()+btnCuatro.getText()); 
    int masClic;      }                                          

Lic. Bernardo C. Hermitaño Atencio 
ISTP: Manuel Seoane Corrales Java Swing  
 

          // TODO add your handling code here: 
    private void btnCincoActionPerformed(java.awt.event.ActionEvent evt)          txtDisplay.setText(txtDisplay.getText()+btnCero.getText()); 
{                                               }                                        
        // TODO add your handling code here:   
        txtDisplay.setText(txtDisplay.getText()+btnCinco.getText());      private void btnPuntoActionPerformed(java.awt.event.ActionEvent evt) 
    }                                          {                                          
          // TODO add your handling code here: 
    private void btnSeisActionPerformed(java.awt.event.ActionEvent evt) {                                         
        if(decimalClic==0){ 
        // TODO add your handling code here:          txtDisplay.setText(txtDisplay.getText()+btnPunto.getText()); 
        txtDisplay.setText(txtDisplay.getText()+btnSeis.getText());          decimalClic=1; 
    }                                                 } 
      }                                         
    private void btnSieteActionPerformed(java.awt.event.ActionEvent evt) {                                          
 
        // TODO add your handling code here:      private void 
        txtDisplay.setText(txtDisplay.getText()+btnSiete.getText());  btnMasMenosActionPerformed(java.awt.event.ActionEvent evt) {                                             
          // TODO add your handling code here: 
    }                                                  
  masmenos=(Double.parseDouble(String.valueOf(txtDisplay.getText()))); 
    private void btnOchoActionPerformed(java.awt.event.ActionEvent evt)          masmenos=masmenos*(‐1); 
{                                                  txtDisplay.setText(String.valueOf(masmenos)); 
        // TODO add your handling code here:      }                                            
        txtDisplay.setText(txtDisplay.getText()+btnOcho.getText());   
    }                                             private void btnMasActionPerformed(java.awt.event.ActionEvent evt) {                               
          // TODO add your handling code here: 
    private void btnNueveActionPerformed(java.awt.event.ActionEvent          
evt) {                                           primerdouble=(Double.parseDouble(String.valueOf(txtDisplay.getText()))); 
        // TODO add your handling code here:          txtDisplay.setText(""); 
        txtDisplay.setText(txtDisplay.getText()+btnNueve.getText());          masClic=1; 
    }                                                  decimalClic=0; 
      }                                       
    private void btnCeroActionPerformed(java.awt.event.ActionEvent evt) {                                         
 

Lic. Bernardo C. Hermitaño Atencio 
ISTP: Manuel Seoane Corrales Java Swing  
 

    private void btnMenosActionPerformed(java.awt.event.ActionEvent          // TODO add your handling code here: 
evt) {                                                   
        // TODO add your handling code here:  segundouble=(Double.parseDouble(String.valueOf(txtDisplay.getText()))); 
                 if(masClic>0){ 
primerdouble=(Double.parseDouble(String.valueOf(txtDisplay.getText())));              totaldouble=primerdouble+segundouble; 
        txtDisplay.setText("");              txtDisplay.setText(String.valueOf(totaldouble)); 
        menosClic=1;              primerdouble=0; 
        decimalClic=0;              segundouble=0; 
    }                                                      masClic=0; 
          } 
    private void btnMultiplicaActionPerformed(java.awt.event.ActionEvent          if(menosClic>0){ 
evt) {                                                            totaldouble=primerdouble‐segundouble; 
        // TODO add your handling code here:              txtDisplay.setText(String.valueOf(totaldouble)); 
                     primerdouble=0; 
primerdouble=(Double.parseDouble(String.valueOf(txtDisplay.getText())));              segundouble=0; 
        txtDisplay.setText("");              menosClic=0; 
        multiClic=1;          } 
        decimalClic=0;          if(multiClic>0){ 
    }                                                           totaldouble=primerdouble*segundouble; 
              txtDisplay.setText(String.valueOf(totaldouble)); 
    private void btnDivideActionPerformed(java.awt.event.ActionEvent evt)              primerdouble=0; 
{                                                        segundouble=0; 
        // TODO add your handling code here:              multiClic=0; 
                 } 
primerdouble=(Double.parseDouble(String.valueOf(txtDisplay.getText())));          if(divClic>0){ 
        txtDisplay.setText("");              totaldouble=primerdouble/segundouble; 
     divClic=1;              txtDisplay.setText(String.valueOf(totaldouble)); 
     decimalClic=0;              primerdouble=0; 
    }                                                       segundouble=0; 
              divClic=0; 
        }    }                
    private void btnIgualActionPerformed(java.awt.event.ActionEvent evt) {                                          

Lic. Bernardo C. Hermitaño Atencio 
ISTP: Manuel Seoane Corrales Java Swing  
 

Lic. Bernardo C. Hermitaño Atencio 

You might also like