Java listens to Windows window events, and now it's almost useless.
When I was in college, I was just beginning to learn Java, and it actually took a lot of effort to listen to Windows window events. Oneself is not a very clever person, a lot of concepts how to see also is not very clear, a lot of logic can only rely on rote memorization, a lot of concepts remember quickly and forget ...
The Java of the year, or did not abandon the field of desktop applications, these years, Java in the desktop application of the PC is almost a failure, but in the Internet and mobile devices, the big shine, at least these, I did not think of the original study.
This similar feature is now almost practically useless.
Stay here, the memory of my lost youth, the memory of the past years of struggle.
1. Java listens for Windows window event source code
PackageCom.listener;ImportJava.awt.Frame;ImportJava.awt.event.WindowEvent;ImportJava.awt.event.WindowListener;/** * Simple listening windows window * * @author Fan Fangming */ Public Abstract class listenerwindowsdemo { Public Static void Main(string[] args) {Frame F =NewFrame (); F.setsize ( -, -); F.setvisible (true);//Register Event listenerF.addwindowlistener (NewWindowListener () { Public void windowactivated(WindowEvent e) { } Public void windowclosed(WindowEvent e) { }/** * When the window form is closed, the listener is windowlistener to listen, and the listener calls the Windowclosing method to handle the action when the window form is closed */ Public void windowclosing(WindowEvent e) {//Through Event object E to get the event source objectFrame F = (frame) e.getsource (); System.out.println (f +"form is closing"); F.dispose (); } Public void windowdeactivated(WindowEvent e) { } Public void windowdeiconified(WindowEvent e) { } Public void windowiconified(WindowEvent e) { } Public void windowopened(WindowEvent e) { } }); }}
2. Final running result
Java.awt.frame[frame0,0,0,400x300,layout=java.awt.borderlayout,title=,resizable,normal] form is closing
A good memory is better than a bad pen. 35-java Monitoring Windows window Events Listener (2)