I am creating a small application using AWT. When I try to close the window, the \"close\" button doesn\'t work.
Here\'s my code:
import java.awt.*;
It's better to use the method public void dispose()
Why should you have to dispose() a java.awt.Window that goes out of scope?
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
dispose();
}
}
);
Try doing it like this:
class ExampleClass implements ActionListener, WindowListener
{
...
f.addWindowListener(this);
...
public void windowDeactivated(WindowEvent e) {}
public void windowDeiconified(WindowEvent e) {}
public void windowIconified(WindowEvent e) {}
public void windowOpened(WindowEvent e) {}
public void windowActivated(WindowEvent e) {}
public void windowClosed(WindowEvent e) {}
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
}
You could do it like this:
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent we){
System.exit(0);
}
});