没有添加windows事件。
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class text3 {
private Frame f;
public text3() {
f = new Frame("Let's study java");
}
public void launchFrame() {
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowevent) {
System.exit(0);
}
});
f.setSize(400, 200);
f.setVisible(true);
}
public static void main(String[] args) {
text3 guiWindow = new text3();
guiWindow.launchFrame();
}
}
import java.awt.*;
import java.awt.event.*;
public class MyFrame extends Frame{
public MyFrame(){
this.setSize(400, 200);
this.enableEvents (AWTEvent.WINDOW_EVENT_MASK);
this.setVisible(true);
}
@Override
protected void processWindowEvent(WindowEvent e)
{
super.processWindowEvent(e);
if (e.getID()==WindowEvent.WINDOW_CLOSING)
{
System.exit (0);
}
}
public static void main(String args[]){
MyFrame f = new MyFrame();
}
}