请看以下程序:import java.awt.*;
import java.awt.event.*;
class Exercise4_6 extends Frame implements ActionListener
{
TextField txt1,txt2,txt3;
Label lab;
Button btn;
Exercise4_6()
{
super("四章练习6");
setSize(400,100);
setVisible(true);
txt1=new TextField(8);
txt2=new TextField(8);
txt3=new TextField(9);
lab=new Label("+");
btn=new Button("=");
setLayout(new FlowLayout());
add(txt1);
add(lab);
add(txt2);
add(btn);
add(txt3);
txt1.addActionListener(this);
txt2.addActionListener(this);
btn.addActionListener(this);
validate();
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==btn||e.getSource()==txt1||e.getSource()==txt2)
{
float x=Integer.paresFloat(txt1.getText());
float y=Integer.paresFloat(txt2.getText());
float z=x+y;
String str=String.valueOf(z);
txt3.setText(str);
}
}
public static void main(String[] args)
{
new Exercise4_6();
}
}
出现:float x=Integer.paresFloat(txt1.getText());
   float y=Integer.paresFloat(txt2.getText());
   找不到符号的问题.
请指点下...........

解决方案 »

  1.   

    txt1.getText()得到的是字符串~~
      

  2.   

    Integer只有parseInt(String string)吧~~
      

  3.   

    Integer有parseInt()
    不报错吗?
      

  4.   

    我就是要个txt1.getText()的是字符串转换为数字啊.
    Integer不只parseInt(String string)吧
    还有paresFloat吧.
      

  5.   


    你看一下JDK的API文档就知道有没有了~~
      

  6.   

    Float 类下才有   Float.parseFloat(txt1.getText());
      

  7.   

    float x= Float.parseFloat(txt1.getText());你是用记事本写的程序吗?
      

  8.   

    我试了一下,就是这一点的错误,
    还有拼写错误,是parseFloat,你写成了paresFloat
    我觉得可以用个工具来做的,比如exlipse,
      

  9.   

    Integer.paresFloat(txt1.getText());
    你的parse打成pares怎么会过呢是Float.parseFloat();
      

  10.   

    不好意思,我也拼错了,是eclipse,呵呵!