请看以下程序: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());
找不到符号的问题.
请指点下...........
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());
找不到符号的问题.
请指点下...........
不报错吗?
Integer不只parseInt(String string)吧
还有paresFloat吧.
你看一下JDK的API文档就知道有没有了~~
还有拼写错误,是parseFloat,你写成了paresFloat
我觉得可以用个工具来做的,比如exlipse,
你的parse打成pares怎么会过呢是Float.parseFloat();