sábado, 30 de noviembre de 2013

Ecuacion de 2do Grado Java Swing

Codigo:
private void B1ActionPerformed(java.awt.event.ActionEvent evt) {                                   
        
        int a;
        int b;
        int c;
        int raiz ;
        double result1 ,result2;
        
        //Transformacion de valores a entero
        a = Integer.parseInt(T1.getText());
        b = Integer.parseInt(T2.getText());
        c = Integer.parseInt(T3.getText());
        
              if(T1.getText().equals("") || T2.getText().equals("") || T3.getText().equals(""))
              {
                  JOptionPane.showMessageDialog(null,"Faltan campos por llenar");
              }
              else
              {
               raiz = (b * b) - (4 * a * c); 
                result1 = (-b + Math.sqrt(raiz)) / (2 * a);
            
                result2 = (-b - Math.sqrt(raiz)) / (2 * a);
               JOptionPane.showMessageDialog(null,"Resultado es:\n" + "X1:  "+result1+"\n"+"X2:  "+ result2 );
                  
              }
    }                                  

    private void b2ActionPerformed(java.awt.event.ActionEvent evt) {                                   
        // Limpiar Cajas de texto
        T1.setText(null);
        T2.setText(null);
        T3.setText(null);
    }                                  

    /**
     * @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(Ventana.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Ventana.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Ventana.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Ventana.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 Ventana().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify                     
    private javax.swing.JButton B1;
    private javax.swing.JTextField T1;
    private javax.swing.JTextField T2;
    private javax.swing.JTextField T3;
    private javax.swing.JButton b2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    // End of variables declaration                   

    void lee() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

   

    
}

IMAGEN:

No hay comentarios:

Publicar un comentario