java applet求助~~~~~~~~~~~~~~~~~~~~~
初学。高人们help me.
题目:编写一个java applet,接受用户输入的一个整数和一个浮点数,求2者的和,差,积,商,较大者和平均值。
-------------------------------------------------------------------------
import java.applet.Applet;
import java.awt.*;
public class Mathematics extends Applet
{
float x; //全局变量,用于取较大者。
Label prompt1;
Label prompt2;
TextField input1;
TextField input2;
String a1= "和是: ";
String a2= "差是: ";
String a3= "积是: ";
String a4= "商是: ";
String a5= "较大的是: ";
String a6= "平均值是: ";
public void init() //Applet初始操作
{
prompt1=new Label( "Enter a integer please: ");
input1=new TextField(3); //input1输入int数
prompt2=new Label( "Enter a floating please: ");
input2=new TextField(6); //input2输入float数
add(prompt1);
add(prompt2);
add(input1);
add(input2); //添加4个对象到界面
}
public void paint(Graphics g)
{
g.drawString(a1+(input1+input2),10,20);
g.drawString(a2+(input1-input2),10,30);
g.drawString(a3+(input1*input2),10,40);
g.drawString(a4+(input1/input2),10,50);
g.drawString(a5+(x?input1:input2),10,60);
g.drawString(a6+([input1+input2]/2),10,70);
}
}
-------------------------------------------
C:\java> javac Mathematics.java
Mathematics.java:34: 运算符 + 不能应用于 java.awt.TextField,java.awt.TextField
g.drawString(a1+(input1+input2),10,20);
^
Mathematics.java:35: 运算符 - 不能应用于 java.awt.TextField,java.awt.TextField
g.drawString(a2+(input1-input2),10,30);
^
Mathematics.java:36: 运算符 * 不能应用于 java.awt.TextField,java.awt.TextField
g.drawString(a3+(input1*input2),10,40);