马老师的视频里,内部类章节,关于持有对方引用,请问这个代码里面在new Monitor()的时候为什么实参要用this而不用f呢,这个代码里面的this和f不是一样吗?谢谢。
import java.awt.Button;
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;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;public class Calculate {
public static void main(String[] args) {
MyFrame11 f = new MyFrame11("Calculate");
f.launchFrame();
}
}class MyFrame11 extends Frame {
TextField tf1,tf2,tf3;
MyFrame11(String str) {
super(str);
}

void launchFrame() {

this.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});

tf1 = new TextField(10);
tf2 = new TextField(10);
tf3 = new TextField(15);
Label l = new Label("+");
Button b = new Button("=");

b.addActionListener(new Monitor_0(this));

this.add(tf1);
this.add(l);
this.add(tf2);
this.add(b);
this.add(tf3);

this.setLocation(500, 400);
this.setLayout(new FlowLayout());
this.pack();
this.setVisible(true);

}
}class Monitor_0 implements ActionListener {

MyFrame11 f = null;
Monitor_0(MyFrame11 f) {
this.f = f;
}

public void actionPerformed(ActionEvent e) {
int n1 = Integer.parseInt(f.tf1.getText());
int n2 = Integer.parseInt(f.tf2.getText());
f.tf3.setText(String.valueOf(n1+n2));
}
}