import java.awt.*;
import java.awt.event.*;
import java.lang.Math;
import java.applet.Applet;
public class qiugen extends Applet implements ActionListener
{
TextField test1,test2,test3,test4,test5;
double a,b,c;
double x1,x2;
Button mybutton;
public void init()
{
test1=new TextField(2);
test2=new TextField(2);
test3=new TextField(2);
test4=new TextField(4);
mybutton=new Button("计算");
test5=new TextField(30);
add(test1);
add(test2);
add(test3);
add(mybutton);
add(test4);
add(test5);
mybutton.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==mybutton)
{
a=Double.parseDouble(test1.getText());
b=Double.parseDouble(test2.getText());
c=Double.parseDouble(test3.getText());
test4.setText(String.valueOf(b*b-4*a*c));
if(b*b-4*a*c>=0)
{
x1=-b+java.lang.Math.sqrt(b*b-4*a*c);//静态方法 自己写的时候碰到错误的地方
x1=-b-java.lang.Math.sqrt(b*b-4*a*c);
test5.setText("根x1="+x1+" 根 x2="+x2);
}
}
}
}
<head>
<meta http-equiv="Content-Type" content="text/html; charset=??????">
<title>一个简单的程序</title>
</head>
<body>
<applet code="qiugen.class" width="400" height="200"></applet>
</body>
</html>
粗略的写了下 具体的可以改进
本文地址:http://com.8s8s.com/it/it15249.htm