Trail: Creating a GUI With JFC/Swing
Lesson: Writing Event Listeners
Section: Implementing Listeners for Commonly Handled Events
How to Write Window Listeners
Home Page > Creating a GUI With JFC/Swing > Writing Event Listeners

How to Write Window Listeners

This section explains how to implement three kinds of window-related event handlers: WindowListener, WindowFocusListener, and WindowStateListener. All three listeners handle WindowEvent objects. The methods in all three event handlers are implemented by the abstract WindowAdapter class.

When the appropriate listener has been registered on a window (such as a frame or dialog), window events are fired just after the window activity or state has occurred. A window is considered as a "focus owner", if this window receives keyboard input.

The following window activities or states can precede a window event:

Problems with the examples? Try Compiling and Running the Examples: FAQs.
Complaints? Compliments? Suggestions? Give us your feedback.

Previous page: How to Write an Undoable Edit Listener
Next page: Listener API Table - all specs in one place