WindowListener is the event Listener window that specializes in processing windows. All the changes in a window. such as window open, close, etc. can use this interface for listening.
Implement WindowListener:
Package Com.beyole.util;import Java.awt.event.windowevent;import Java.awt.event.windowlistener;public class Mywindoweventhandle implements WindowListener {@Overridepublic void windowopened (WindowEvent e) {System.out.println (" windowopened---> form is open ");} @Overridepublic void windowclosing (WindowEvent e) {System.out.println ("windowclosing---> Form closed");} @Overridepublic void windowclosed (WindowEvent e) {System.out.println ("windowclosed---> Form closed");} @Overridepublic void Windowiconified (WindowEvent e) {System.out.println ("windowiconified---> Form minimized");} @Overridepublic void Windowdeiconified (WindowEvent e) {System.out.println ("windowdeiconfied---> Form minimized Recovery");} @Overridepublic void windowactivated (WindowEvent e) {System.out.println ("windowactivated---> Form selected");} @Overridepublic void windowdeactivated (WindowEvent e) {System.out.println ("windowdeactivated---> Cancel form is selected");}}
Simply having a listener is not enough. You also need to register for monitoring when the component is in use. This ability to handle, directly using the window Addwindowlistener (Listener object) method can be registered event monitoring
Package Com.beyole.util;import Java.awt.color;import Javax.swing.jframe;public class MyWindowEventFrame01 {public static void Main (string[] args) {JFrame frame=new JFrame ("Crystal"); Frame.addwindowlistener (new Mywindoweventhandle () ); Frame.setsize, Frame.setbackground (Color.White); frame.setlocation (+); frame.setvisible (True);}}
Program:
Results:
Java Swing Interface Programming (+)---event handling: Window events