For example, windows don't close on their own. You have to
explicitly close them. The following subclass of Frame
puts up a window that responds to efforts to close it by calling
setVisible(false)
and dispose()
.
import java.awt.*;
import java.awt.event.*;
public class ClosableFrame extends Frame implements WindowListener {
public ClosableFrame() {
this.addWindowListener(this);
}
public ClosableFrame(String title) {
super(title);
this.addWindowListener(this);
}
public void windowClosing(WindowEvent evt) {
this.setVisible(false);
this.dispose();
}
public void windowOpened(WindowEvent evt) {}
public void windowClosed(WindowEvent evt) {}
public void windowIconified(WindowEvent evt) {}
public void windowDeiconified(WindowEvent evt) {}
public void windowActivated(WindowEvent evt) {}
public void windowDeactivated(WindowEvent evt) {}
}