import java.awt.*;
import java.awt.event.*;public class a {
public static void main(String[] args) {
new TFFrame();
}
}class TFFrame extends Frame {
TextField num1,num2,num3; TFFrame(){
num1 = new TextField(5);
num2 = new TextField(5);
num3 = new TextField(10);
Label jia = new Label("+");
Button result = new Button("=");
add(num1);
add(jia);
add(num2);
add(result);
add(num3);
setLayout(new FlowLayout());
pack();
setVisible(true);
result.addActionListener(new jianting(this));
}
}
class jianting implements ActionListener {
TFFrame frame = null;
public jianting(TFFrame frame) {
this.frame=frame;
}
public void actionPerformed(ActionEvent e) {
int n1 = Integer.parseInt(frame.num1.getText());
int n2 = Integer.parseInt(frame.num2.getText());
frame.num3.setText=("" + (n1+n2));
}
}

解决方案 »

  1.   


    class jianting implements ActionListener {
        TFFrame frame = null;
        public jianting(TFFrame frame) {
            this.frame=frame;
        }
        public void actionPerformed(ActionEvent e) {
            int n1 = Integer.parseInt(frame.num1.getText());
            int n2 = Integer.parseInt(frame.num2.getText());
            errorow:frame.num3.setText=("" + (n1+n2));
        }
    }改为:class jianting implements ActionListener {
        TFFrame frame = null;
        public jianting(TFFrame frame) {
            this.frame=frame;
        }
        public void actionPerformed(ActionEvent e) {
            int n1 = Integer.parseInt(frame.num1.getText());
            int n2 = Integer.parseInt(frame.num2.getText());
            errorrow:frame.num3.setText("" + (n1+n2));  //函数写法错了,估计是笔误
        }
    }
      

  2.   

     frame.num3.setText=("" + (n1+n2));
    多了“=”
    用myeclipse很容易找出来
      

  3.   

    import java.awt.*;
    import java.awt.event.*;public class a {
        public static void main(String[] args) {
            new TFFrame();
        }
    }class TFFrame extends Frame {
        TextField num1,num2,num3;    TFFrame(){
            num1 = new TextField(5);
            num2 = new TextField(5);
            num3 = new TextField(10);
            Label jia = new Label("+");
            Button result = new Button("=");
            add(num1);
            add(jia);
            add(num2);
            add(result);
            add(num3);
            setLayout(new FlowLayout());
            pack();
            setVisible(true);
            result.addActionListener(new jianting(this));
        }
    }
    class jianting implements ActionListener {
        TFFrame frame = null;
        public jianting(TFFrame frame) {
            this.frame=frame;
        }
        public void actionPerformed(ActionEvent e) {
            int n1 = Integer.parseInt(frame.num1.getText());
            int n2 = Integer.parseInt(frame.num2.getText());
            frame.num3.setText=("" + (n1+n2));你这里干嘛加的=号?
        }
    }
      

  4.   


    有个warning在TFFramehttp://www.blogjava.net/invisibletank/archive/2007/11/15/160684.html希望对你有用