I'm trying to listen for events on a single Frame via WindowStateListener.
import java.awt.Frame;
import java.awt.Label;
import java.awt.event.WindowStateListener;
import java.awt.event.WindowEvent;
public class UserInterface implements WindowStateListener
{
public static void main(final String[] arguments)
{
UserInterface userInterface = new UserInterface();
}
public UserInterface()
{
Frame frame = new Frame("Graphics Example");
frame.addWindowStateListener(this);
frame.add(new Label("Hello, world!");
frame.pack();
frame.setVisible(true);
}
public void windowStateChanged(WindowEvent event)
{
System.out.println(event.paramString();
}
}
It's working fine for minimization events, but not close events. WINDOW_CLOSING is definitely a valid WindowEvent value, and it's definitely something that Frame can throw. So why isn't it being passed to windowStateChanged()?
WindowStateListeners are not notified of the window closing events. They are only notified of changes to the window's state, such as iconified or de-iconified. If you want close events, implement WindowListener (or extend WindowAdapter). This tutorial explains it http://download.oracle.com/javase/tutorial/uiswing/events/windowlistener.html.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With