日期:2014-05-20  浏览次数:20796 次

请问这个为什么编译不通过呢?
Java code
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));
    }
}


------解决方案--------------------
Java code

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));
    }
}

------解决方案--------------------
frame.num3.setText=("" + (n1+n2));
多了“=”
用myeclipse很容易找出来
------解决方案--------------------
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));你这里干嘛加的=号?
}
}
------解决方案--------------------

有个warning在TFFrame

http://www.blogjava.net/invisibletank/archive/2007/11/15/160684.html

希望对你有用