现在改过来了,可以运行,对比一下吧,问题就不大,只是一些语法问题,还有一些类没有导进来,LZ应该不是在集成环境下写的吧,所以才有这样的语法错误,建议用
JBuilder,Eclipse,Netbeans等集成环境吧.这样容易上手
import java.awt.Button;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Label;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class jiafa implements ActionListener
{
Frame f;
Label lab1,lab2,lab3;
TextField tf1,tf2,tf3;
Button bt1,bt2;
public jiafa()
{
f=new Frame("加法器");
f.setSize(130,60);
f.setBackground(Color.green);
f.setLocation(400,200);
lab1=new Label("加数1");
lab2=new Label("加数2");
lab3=new Label("结果");
tf1=new TextField(30);
tf2=new TextField(30);
tf3=new TextField(30);
bt1=new Button("运算");
bt2=new Button("清零");
f.setLayout(new FlowLayout());
f.add(lab1);
f.add(tf1);
f.add(lab2);
f.add(tf2);
f.add(lab3);
f.add(tf3);
f.add(bt1);
f.add(bt2);
bt1.addActionListener(this);
bt2.addActionListener(this);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
String st1=tf1.getText();
String st2=tf2.getText();
String st3;
int a,b,c;
a=Integer.parseInt(st1);
b=Integer.parseInt(st2);
if(e.getSource()==bt1)
{
c=a+b;
st3=st1+"+"+st2+"="+c;
tf3.setText(st3);
}
else
{
tf1.setText(" ");
tf2.setText(" ");
tf3.setText(" ");
}
}
public static void main(String args[])
{
new jiafa();
}
}
[此贴子已经被作者于2007-10-31 22:56:28编辑过]