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