import java.awt.*;
import java.awt.event.*;public class TFFr {
public static void main(String[] args) {
new TfFrame();     
}
}class TfFrame extends Frame{
TfFrame(){
TextField t1 = new TextField();
TextField t2 = new TextField();
TextField t3 = new TextField();
Label le = new Label("+");
Button ba = new Button("=");
ba.addActionListener(new Mymonitor(this));
this.setLayout(new FlowLayout());
add(t1);
add(le);
add(t2);
add(ba);
add(t3);
pack();
this.setLocation(200, 200);
this.setVisible(true);
}
}
 class Mymonitor implements ActionListener{ 
 TfFrame m = null;
 public Mymonitor (TfFrame m){
 this.m =m;
}
public void actionPerformed(ActionEvent e){
int mm = Integer.parseInt(m.t1.getText());
int nn = Integer.parseInt(m.t2.getText());
m.t3.SetText(""+(mm+nn));
}
 }

解决方案 »

  1.   

    import java.awt.*;
    import java.awt.event.*;public class TFFr {    public static void main(String[] args) {
            new TfFrame();
        }
    }class TfFrame extends Frame {    TextField t1 = new TextField();
        TextField t2 = new TextField();
        TextField t3 = new TextField();    TfFrame() {        Label le = new Label("+");
            Button ba = new Button("=");
            ba.addActionListener(new Mymonitor(this));
            this.setLayout(new FlowLayout());
            add(t1);
            add(le);
            add(t2);
            add(ba);
            add(t3);
            pack();
            this.addWindowListener(new WindowAdapter() {            @Override
                public void windowClosing(WindowEvent e) {
                    System.exit(0);
                }
            
            });
            this.setLocation(200, 200);
            this.setVisible(true);    }
    }class Mymonitor implements ActionListener {    TfFrame m = null;    public Mymonitor(TfFrame m) {
            this.m = m;
        }    public void actionPerformed(ActionEvent e) {
            int mm = Integer.parseInt(m.t1.getText());
            int nn = Integer.parseInt(m.t2.getText());
            m.t3.setText("" + (mm + nn));
        }
    }
      

  2.   

    区分方法中的局部变量和类的field。