Mod: lee las reglas del foro, no debes escribir en mayúsculas, los codigos ven en etiquetas GeSHi, las cosas van en su respuesctivo subforo... tema corregido y movido
saludos, tengo un error en mi ejercicio y me gustaria que me ayuden a encontrar el problema; es sobre la resolucion de una ecuacion cuadratica con applets...
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.applet.Applet;
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.lang.Math;
/**
*
* @author
*/
public class EcuacionApplet extends Applet implements ActionListener {
/**
* Initialization method that will be called after the applet is loaded into
* the browser.
*/
Label l1, l2, l3, l4, l5;
TextField t1, t2, t3, t4, t5,t6,t7;
Button b;
public void init() {
// TODO start asynchronous download of heavy resources
// --> DECLARANDO MIS ETIQUETAS Y CAJAS DE TEXTO
l1 = new Label("a");
t1 = new TextField();
l2 = new Label("b");
t2 = new TextField();
l3 = new Label("c");
t3 = new TextField();
l4 = new Label("Raiz 1");
t4 = new TextField(" ");
l5 = new Label("Raiz 2");
t5 = new TextField(" ");
b = new Button("CALCULAR");
t6= new TextField(" ");
t7= new TextField(" ");
// --> AÑADIENDO BOTONES Y LABELS
add(l1);
add(t1);
add(l2);
add(t2);
add(l3);
add(t3);
add(b); //-->BOTON
add(l4);
add(t4);
add(l5);
add(t5);
add(t6);
add(t7);
b.addActionListener(this);
// TODO overwrite start(), stop() and destroy() methods
}
//-->OPERACIONES LOGICAS DEL BOTON CALCULAR
public void actionPerformed(ActionEvent ae) {
// var a=num,b=num2,c=num3
double num=Double.parseDouble(t1.getText());
double num2=Double.parseDouble(t2.getText());
double num3=Double.parseDouble(t3.getText());
// descarga en la variable d el valor de b^2-4ac
double d=(Math.pow(num2,2.0)-(4*num*num3));
// calcula las raices de la ecuación
double raiz1=((-num2)+Math.sqrt(d))/(2*num);
double raiz2=((-num2)-Math.sqrt(d))/(2*num);
// compara la variable d
if (d==0)
{
// las raices son igulaes
t6.setText(""+raiz1);
t7.setText(""+raiz2);
}
if (d>0)
{
// tiene 2 raices diferentes
t6.setText(""+raiz1);
t7.setText(""+raiz2);
}
if (d<0) //--> CONDICION DE VALORES IMAGINARIOS
{
t6.setText("IMAGINARIA");
t7.setText("IMAGINARIA");
}
}
//---> POSICIONANDO ENCABEZADO
public void paint(Graphics g) {
g.drawString("Resolucion Ecuación Cuadratica aX^2+bx+c=0", 10, 110);
g.drawString("Lenguaje de Programacion", 11, 130);
}
}