A good memory is better than a bad pen. 35-java Monitoring Windows window Events Listener (2)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.