Java interface-Focus event class

Source: Internet
Author: User

[Related information]
The Focus event class (FocusEvent) refers to a focus event that occurs when a component of the user program interface loses focus (that is, when the focus moves from one object to another).
Using focus events You must add an event handler for the Focuslistener interface to the component that contains the following two methods:
1) void focusgained (FocusEvent e): Occurs when the focus is obtained.
2) void Focuslost (FocusEvent e): Occurs when the focus is lost.

[Specific program Implementation]

 PackageSup.orange.learn;Importjava.awt.*;Importjava.awt.event.*;/*** Created by Re-x on 10/28/14.*/ Public classFocuseventdemoextendsframe{TextArea TextArea;    TextField TextField;  PublicFocuseventdemo () {Super();    Init (); }     Public Static voidMain (string[] args) {NewFocuseventdemo (); }     Public voidinit () {setlayout (NewGridLayout (2, 1)); TextArea=NewTextArea (); Textarea.addfocuslistener (NewFocuslistener () {@Override Public voidfocusgained (focusevent e) {Textarea.settext ("Gained"); } @Override Public voidFocuslost (focusevent e) {Textarea.settext ("Lost");        }        }); TextField=NewTextField (); Textfield.addfocuslistener (NewFocuslistener () {@Override Public voidfocusgained (focusevent e) {Textfield.settext ("TextField gained"); } @Override Public voidFocuslost (focusevent e) {Textfield.settext ("TextField Lost");        }        });        Add (textarea);        Add (TextField); Addwindowlistener (NewWindowadapter () {@Override Public voidwindowclosing (windowevent e) {Super. windowclosing (e);                Dispose (); System.exit (0);        }        }); SetSize (200, 500); SetVisible (true); }}

Java interface-Focus event class

Related Article

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.