请问,运行第64行代码关闭不了程序,是哪里有问题呀?
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 javax.swing.JFrame;
public class TestTF_3 {
public static void main(String[] args) {
new TF().launch();
}
}
class TF extends JFrame {
public TextField tf1, tf2, tf3;
public void launch() {
Frame f = new Frame();
tf1 = new TextField(30);
tf2 = new TextField(30);
tf3 = new TextField(30);
Button bn = new Button("=");
Label lb = new Label("+");
f.setLayout(new FlowLayout());
f.add(tf1);
f.add(lb);
f.add(tf2);
f.add(bn);
f.add(tf3);
bn.addActionListener(new MyMonitor2());
f.pack();
f.setVisible(true);
// f.addWindowListener(new WindowAdapter() { //正常关闭
// @Override
// public void windowClosing(WindowEvent e) {
// System.exit(-1);
// }
// });
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //error 64行
//this.setDefaultCloseOperation(3); //error
}
class MyMonitor2 implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
int num1 = Integer.parseInt(tf1.getText());
int num2 = Integer.parseInt(tf2.getText());
int num3 = num1 + num2;
tf3.setText(num3 + "");
}
}
}