Java Programming | Window Listener in Java | Java Window Listener | Java Swing tutorial | Java GUI
Programming Guru
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.
The listener interface for receiving window events. The class that is interested in processing a window event either implements this interface (and all the methods it contains) or extends the abstract WindowAdapter class (overriding only the methods of interest). The listener object created from that class is then registered with a Window using the window's addWindowListener method. When the window's status changes by virtue of being opened, closed, activated or deactivated, iconified or deiconified, the relevant method in the listener object is invoked, and the WindowEvent is passed to it.
#ProgrammingGuru #Javaprogramming #javaprogrammingforbeginners #javaprogrammingfullcourse #javaprogrammingprojects #java #javatutorial #Windowlistenerinjava #Javawindowlistener #Javaswingtutorial #JavaGui #addwindowlistenerinjava
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:
Opening a window — Showing a window for the first time.
Closing a window — Removing the window from the screen.
Iconifying a window — Reducing the window to an icon on the desktop.
Deiconifying a window — Restoring the window to its original size.
Focused window — The window which contains the "focus owner".
Activated window (frame or dialog) — This window is either the focused window, or owns the focused window.
Deactivated window — This window has lost the focus. For more information about focus, see the AWT Focus Subsystem specification.
Maximizing the window — Increasing a window's size to the maximum allowable size, either in the vertical direction, the horizontal direction, or both directions.
The WindowListener interface defines methods that handle most window events, such as the events for opening and closing the window, activation and deactivation of the window, and iconification and deiconification of the window.
The other two window listener interfaces are WindowFocusListener and WindowStateListener. WindowFocusListener contains methods to detect when the window becomes the focus owner or it loses the focus owner status. WindowStateListener has a single method to detect a change to the state of the window, such as when the window is iconified, deiconified, maximized, or restored to normal.
While you can use the WindowListener methods to detect some window states, such as iconification, there are two reasons why a WindowStateListener might be preferable: it has only one method for you to implement, and it provides support for maximization.
SWING - WindowListener Interface The class which processes the WindowEvent should implement this interface. The object of that class must be registered with a component. The object can be registered using the addWindowListener() method.
Follow my Facebook Page : https://www.facebook.com/105940115222549 Follow me on Instagram : https://www.instagram.com/p/CViUlw2sOMi Follow me on tumblr : http://programming-guru.tumblr.com Follow me on reddit : https://www.reddit.com/u/Programming_guru1?utm_medium=android_app&utm_source=share ... https://www.youtube.com/watch?v=hPsjJBmPt68
23065905 Bytes