lunes, 23 de abril de 2007

hallar las raices de un polinomio de grado 2

/*
* NewJFrame.java
*
* Created on 16 de abril de 2007, 07:19 PM
*/

/**
*
* @author ALUMNO
*/
public class NewJFrame extends javax.swing.JFrame {

/** Creates new form NewJFrame */
public NewJFrame() {
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.
*/
// //GEN-BEGIN:initComponents
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextPane1 = new javax.swing.JTextPane();
jScrollPane2 = new javax.swing.JScrollPane();
jTextPane2 = new javax.swing.JTextPane();
jScrollPane3 = new javax.swing.JScrollPane();
jTextPane3 = new javax.swing.JTextPane();
jScrollPane4 = new javax.swing.JScrollPane();
jTextPane4 = new javax.swing.JTextPane();
jButton1 = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
jLabel5 = new javax.swing.JLabel();
jScrollPane5 = new javax.swing.JScrollPane();
jTextPane5 = new javax.swing.JTextPane();


setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("a");

jTextPane1.setName("A");
jScrollPane1.setViewportView(jTextPane1);

jScrollPane2.setName("B");
jTextPane2.setName("B");
jScrollPane2.setViewportView(jTextPane2);

jTextPane3.setEditable(false);
jTextPane3.setName("R1");
jScrollPane3.setViewportView(jTextPane3);

jTextPane4.setEditable(false);
jTextPane4.setName("R2");
jScrollPane4.setViewportView(jTextPane4);

jButton1.setText("Raices");
jButton1.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent evt)
{
jButton1ActionPerformed(evt);
}
});

jLabel2.setText("b");

jLabel3.setText("Raiz 1");

jLabel4.setText("Raiz 2");

jLabel5.setText("c");

jTextPane5.setName("C");
jScrollPane5.setViewportView(jTextPane5);

org.jdesktop.layout.GroupLayout layout = new
org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(

layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(org.jdesktop.layout.GroupLayout.TRAILING,
layout.createSequentialGroup()
.addContainerGap(306, Short.MAX_VALUE)
.add(jButton1)
.add(120, 120, 120))
.add(org.jdesktop.layout.GroupLayout.TRAILING,
layout.createSequentialGroup()

..add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(org.jdesktop.layout.GroupLayout.LEADING,
layout.createSequentialGroup()
.add(21, 21, 21)

..add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jLabel5)

..add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel1)
.add(jLabel2)))
.add(14, 14, 14)

..add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING,
false)
.add(jScrollPane5)
.add(jScrollPane2)
.add(jScrollPane1,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE)))
.add(layout.createSequentialGroup()
.addContainerGap()

..add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel3)
.add(jScrollPane3,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 226,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))

..add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(14, 14, 14)
.add(jScrollPane4,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 196,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(layout.createSequentialGroup()
.add(81, 81, 81)
.add(jLabel4)))
.addContainerGap())
);
layout.setVerticalGroup(

layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.addContainerGap()

..add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jScrollPane1,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel1))
.add(15, 15, 15)

..add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
.add(jScrollPane2,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(jLabel2))
.add(25, 25, 25)

..add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel5)
.add(jScrollPane5,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)

..add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(jLabel3)
.add(jLabel4))

.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED,
17, Short.MAX_VALUE)

..add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING,
false)
.add(org.jdesktop.layout.GroupLayout.LEADING,
jScrollPane4)
.add(org.jdesktop.layout.GroupLayout.LEADING,
jScrollPane3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 47,
Short.MAX_VALUE))
.add(21, 21, 21)
.add(jButton1)
.addContainerGap(49, Short.MAX_VALUE))
);
pack();
}//
//GEN-END:initComponents

private void jButton1ActionPerformed(java.awt.event.ActionEvent
evt)
{//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
double a, b, c;
double r1, r2;
String str1,str2;
a = Double.parseDouble(jTextPane1.getText());
b = Double.parseDouble(jTextPane2.getText());
c = Double.parseDouble(jTextPane5.getText());

r1=(-b+Math.sqrt(b*b-4*a*c))/(2*a);
r2=(-b-Math.sqrt(b*b-4*a*c))/(2*a);

str1 = String.valueOf(r1);
str2 = String.valueOf(r2);
jTextPane3.setText(str1);
jTextPane4.setText(str2);
}//GEN-LAST:event_jButton1ActionPerformed

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JScrollPane jScrollPane4;
private javax.swing.JScrollPane jScrollPane5;
private javax.swing.JTextPane jTextPane1;
private javax.swing.JTextPane jTextPane2;
private javax.swing.JTextPane jTextPane3;
private javax.swing.JTextPane jTextPane4;
private javax.swing.JTextPane jTextPane5;
// End of variables declaration//GEN-END:variables

}

No hay comentarios: