You are on page 1of 2

import java.awt.

*;
import java.applet.*;
import java.awt.event.*;
import java.lang.Math.*;

// disabled-applet>

public class Cuadratica extends Applet implements ActionListener {


Label l1, l2, l3, l4, l5;
TextField t1, t2, t3, t4, t5;
Button b;

public Cuadratica() {
l1 = new Label("a");
t1 = new TextField();
l2 = new Label("b");
t2 = new TextField();
l3 = new Label("c");
t3 = new TextField();
l4 = new Label ("X1");
t4 = new TextField();
l5 = new Label("x2");
t5 = new TextField();
b = new Button("Calcular");
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(b);
add(l4);
add(t4);
add(l5);
add(t5);
add(b);
b. addActionListener(this);

}
public void actionPerformed(ActionEvent ae) {
double a,b,c,x1,x2,r;
a = Double.parseDouble(t1.getText());
b = Double.parseDouble(t2.getText());
c = Double.parseDouble(t3.getText());
r = Math.sqrt(Math.pow(b,2.0)-(4*a*c));
x1= ((-b+r)/(2.0*a));
x2= ((-b-r)/(2.0*a));
t4.setText(""+x1);
t5.setText(""+x2);
}
}

You might also like