Javase window event Class (WindowEvent) implementation

Source: Internet
Author: User

{Related Information}
Window events (windowevent) are events that change the state of a window, such as when the Window object is opened, closed, activated, deactivated, or the focus shifts to the window.
And the events generated by the focus removal typically occur on objects such as Window, Frame, Dialog, and so on. Using window events You must add an event handler for the component that implements the WindowListener interface, which contains the following 7 methods:
void windowactivated (WindowEvent e): Occurs when a window is activated
void windowclosed (WindowEvent e): Occurs after a window is closed
void Windowclosing (WindowEvent e): Occurs during window closing
void windowdeactivated (WindowEvent e): Occurs when the window is no longer in the active state
void Windowdeiconified (WindowEvent e): Occurs when the window size is from smallest to normal
void Windowiconified (WindowEvent e): Occurs from normal to minimum window
void windowopened (WindowEvent e): Occurs when the window is opened for the first time

{Related Code}

 PackageSup.orange.learn;Importjava.awt.*;Importjava.awt.event.WindowEvent;ImportJava.awt.event.WindowListener;/*** Created by Re-x on 11/2/14.*/ Public classWindoweventdemoextendsFrame {string string=NULL;  PublicWindoweventdemo () {Super();    Init (); }     Public Static voidMain (string[] args) {NewWindoweventdemo (); }     Public voidinit () {Addwindowlistener (NewWindowListener () {@Override Public voidwindowopened (WindowEvent e) {string= "Window Opened";                System.out.println (string);            Repaint (); } @Override Public voidwindowclosing (WindowEvent e) {string= "Window Closing";                System.out.println (string); SetVisible (false);                Dispose (); System.exit (0); } @Override Public voidwindowclosed (WindowEvent e) {string= "Window Closed";                System.out.println (string);            Repaint (); } @Override Public voidwindowiconified (WindowEvent e) {string= "Window Iconified";                System.out.println (string);            Repaint (); } @Override Public voidwindowdeiconified (WindowEvent e) {string= "Window Deiconified";                System.out.println (string);            Repaint (); } @Override Public voidwindowactivated (WindowEvent e) {string= "Window Activated";                System.out.println (string);            Repaint (); } @Override Public voidwindowdeactivated (WindowEvent e) {string= "Window deactivated";                System.out.println (string);            Repaint ();        }        }); SetSize (200, 200); SetVisible (true); }     Public voidPaint (Graphics g) {g.drawstring (string,30, 100); }}

Javase window event Class (WindowEvent) implementation

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.