it is not finished yet cuz i have some(read MANY) problems.
At this moment I want the values of X1 and X2 to be displayed
in a messageDialog Box. Also I get
possible loss of precision warning when I compile.
help
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
public class Kvadratna extends java.applet.Applet implements ActionListener {
Label aa = new Label("a:");
Label bb = new Label("b:");
Label cc = new Label("c:");
TextField A = new TextField();
TextField B = new TextField();
TextField C = new TextField();
Button otkaz = new Button("Reset");
Button calc = new Button("Calculate");
float X1, X2, a, b, c;
public void init() {
setLayout(new GridLayout(4,2));
add(aa);
add(A);
add(bb);
add(B);
add(cc);
add(C);
add(otkaz);
add(calc);
a = Double.parseDouble(aa.getText()); //when I compile get here possible loss of precision
b = Double.parseDouble(bb.getText()); //possible loss of precision
c = Double.parseDouble(cc.getText()); //possible loss of precision
X1 = ((-b)-Math.sqrt((b*b-4*a*c)))/(2*a); //possible loss of precision
X2 = ((-b)+Math.sqrt((b*b-4*a*c)))/(2*a); //possible loss of precision
calc.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
JOptionPane.showMessageDialog(this, "the numbers are: "+X1+" , "+X2);
}
}
EDIT: modified title ~ jayman9

New Topic/Question
Reply




MultiQuote




|