Javatpoint Logo
Javatpoint Logo

Java WindowListener Interface

The Java WindowListener is notified whenever you change the state of window. It is notified against WindowEvent. The WindowListener interface is found in java.awt.event package. It has three methods.

WindowListener interface declaration

The declaration for java.awt.event.WindowListener interface is shown below:

Methods of WindowListener interface

The signature of 7 methods found in WindowListener interface with their usage are given below:

Sr. no. Method signature Description
1. public abstract void windowActivated (WindowEvent e); It is called when the Window is set to be an active Window.
2. public abstract void windowClosed (WindowEvent e); It is called when a window has been closed as the result of calling dispose on the window.
3. public abstract void windowClosing (WindowEvent e); It is called when the user attempts to close the window from the system menu of the window.
4. public abstract void windowDeactivated (WindowEvent e); It is called when a Window is not an active Window anymore.
5. public abstract void windowDeiconified (WindowEvent e); It is called when a window is changed from a minimized to a normal state.
6. public abstract void windowIconified (WindowEvent e); It is called when a window is changed from a normal to a minimized state.
7. public abstract void windowOpened (WindowEvent e); It is called when window is made visible for the first time.

Methods inherited by the WindowListener

This interface inherits methods from the EventListener interface.

Working of WindowListener interface

  • If a class needs to process some Window events, an object should exist which can implement the interface.
  • As the object is already registered with Listener, an event will be generated on all the states of window.
  • This helps in generation of invocation of relevant method in listener's object. And then WindowEvent is passed after invocation.

Java WindowListener Example

In the following example, we are going to implement all the method of WindowListener interface one by one.

WindowExample.java

Output:

java awt windowlistener example 1
java awt windowlistener example 2





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA