Java Event Authorization processing mechanism

Source: Internet
Author: User

1, in the program if you want to accept and handle event *event, you must define the corresponding event-handling class, which must implement the interface *listener with the event.
2. After you define the event-handling class, you must register the event-handling object on the event source and register the Listener with Method Add*listener (*listener).

The following example:

 PackageSup.orange.learn;Importjava.awt.*;Importjava.awt.event.ActionEvent;ImportJava.awt.event.ActionListener;ImportJava.awt.event.WindowAdapter;Importjava.awt.event.WindowEvent;/*** Created by Re-x on 10/26/14.*/ Public classEventmanagerdemo { Public Static voidMain (string[] args) {FinalFrame f =NewFrame ("Test"); Button b=NewButton ("Pressme"); B.addactionlistener (NewButtonhandler ()); F.setlayout (NewFlowLayout ());        F.add (b); F.setsize (200, 300); F.addwindowlistener (NewWindowadapter () {@Override Public voidwindowclosing (windowevent e) {Super. windowclosing (e); System.exit (0);        }        }); F.setvisible (true); }}classButtonhandlerImplementsActionListener { Public voidactionperformed (ActionEvent e) {System.out.println ("Got It!"); }}

Java Event Authorization processing mechanism

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.