jueves, 29 de agosto de 2013

Ejercicio Formulario Suma, Restar, Multiplicar y Dividir (Línea de Código)

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package paqSuma;

/**
 *
 * @author Diego Leonardo
 */
public class jSuma extends javax.swing.JFrame {

    /**
     * Creates new form jSuma
     */
    public jSuma() {
        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.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                         
    private void initComponents() {

        jTxtNumero1 = new javax.swing.JTextField();
        jTxtNumero2 = new javax.swing.JTextField();
        jBtnSumar = new javax.swing.JButton();
        jLblResultado = new javax.swing.JLabel();
        jBtnRestar = new javax.swing.JButton();
        jBtnMultiplicar = new javax.swing.JButton();
        jBtnDividir = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jBtnSumar.setText("Suma");
        jBtnSumar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnSumarActionPerformed(evt);
            }
        });

        jLblResultado.setText("Resultado");

        jBtnRestar.setText("Resta");
        jBtnRestar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnRestarActionPerformed(evt);
            }
        });

        jBtnMultiplicar.setText("Multiplicacion");
        jBtnMultiplicar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnMultiplicarActionPerformed(evt);
            }
        });

        jBtnDividir.setText("Division");
        jBtnDividir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBtnDividirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jBtnSumar)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(48, 48, 48)
                        .addComponent(jLblResultado)
                        .addContainerGap(235, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(jTxtNumero2, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jBtnRestar)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jBtnMultiplicar)))
                        .addGap(18, 18, 18)
                        .addComponent(jBtnDividir)
                        .addGap(27, 27, 27))))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(65, 65, 65)
                .addComponent(jTxtNumero1, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(54, 54, 54)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTxtNumero1, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jTxtNumero2, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(49, 49, 49)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jBtnSumar)
                    .addComponent(jBtnRestar)
                    .addComponent(jBtnMultiplicar)
                    .addComponent(jBtnDividir))
                .addGap(36, 36, 36)
                .addComponent(jLblResultado)
                .addContainerGap(87, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                       

    private void jBtnSumarActionPerformed(java.awt.event.ActionEvent evt) {                                         
          // TODO add your handling code here:
          Integer numero1, numero2;
          numero1=Integer.parseInt(jTxtNumero1.getText()); //Asignacion
          //parseint es un metodo para convertir
          // de letras a números
          numero2=Integer.parseInt(jTxtNumero2.getText());
          Integer Resultado=0; //Inicializar una variable en cero
          Resultado=numero1+numero2;
          jLblResultado.setText("Resultado: "+Resultado);
      
    }                                        

    private void jBtnRestarActionPerformed(java.awt.event.ActionEvent evt) {                                          
        // TODO add your handling code here:
        Integer numero1, numero2;
          numero1=Integer.parseInt(jTxtNumero1.getText()); //Asignacion
          //parseint es un metodo para convertir
          // de letras a números
          numero2=Integer.parseInt(jTxtNumero2.getText());
          Integer Resultado=0; //Inicializar una variable en cero
          Resultado=numero1-numero2;
          jLblResultado.setText("Resultado: "+Resultado);
    }                                         

    private void jBtnMultiplicarActionPerformed(java.awt.event.ActionEvent evt) {                                               
        // TODO add your handling code here:
        Integer numero1, numero2;
          numero1=Integer.parseInt(jTxtNumero1.getText()); //Asignacion
          //parseint es un metodo para convertir
          // de letras a números
          numero2=Integer.parseInt(jTxtNumero2.getText());
          Integer Resultado=0; //Inicializar una variable en cero
          Resultado=numero1*numero2;
          jLblResultado.setText("Resultado: "+Resultado);
    }                                              

    private void jBtnDividirActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
          Integer numero1, numero2;
          numero1=Integer.parseInt(jTxtNumero1.getText()); //Asignacion
          //parseint es un metodo para convertir
          // de letras a números
          numero2=Integer.parseInt(jTxtNumero2.getText());
          Integer Resultado=0; //Inicializar una variable en cero
          Resultado=numero1/numero2;
          jLblResultado.setText("Resultado: "+Resultado);
    }                                          

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(jSuma.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(jSuma.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(jSuma.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(jSuma.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new jSuma().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                    
    private javax.swing.JButton jBtnDividir;
    private javax.swing.JButton jBtnMultiplicar;
    private javax.swing.JButton jBtnRestar;
    private javax.swing.JButton jBtnSumar;
    private javax.swing.JLabel jLblResultado;
    private javax.swing.JTextField jTxtNumero1;
    private javax.swing.JTextField jTxtNumero2;
    // End of variables declaration                  
}

No hay comentarios:

Publicar un comentario