Home : Course Map : Chapter 7 : Java :
Event Processing
JavaTech
Course Map
Chapter 7

Introduction
Event Overview
Event Processing
Button Events
  Demo 1
 Demo 2
Mouse Events
  Demo3

More Components
  Demo 4  Demo 5
  Demo 6  Demo 7

LayoutManagers-1
  Demo 8     Demo 9
  Demo 10  Demo 11
  Demo 12

LayoutManagers-2
  Demo 13  Demo 14
  Demo 15  Demo 16
  Demo 17

Inner Classes
Anonymous Class
Adapter Classes
  Demo 18  Demo 19
Frames & Menus
  Demo 20  Demo 21
Exercises

    Supplements
AWT Components
  Button
     Demo 1
  Canvas
     Demo 2
  AWT GUI Demo
     Demo 3
Swing Dialogs
JOptionPane Dialog
  Demo 1
JDialog
  Demo 2
UI Enhancement: P1
  Demo 1   Demo 2
  Demo 3

UI Enhancement: P2
  Demo 1
     About JavaTech
     Codes List
     Exercises
     Feedback
     References
     Resources
     Tips
     Topic Index
     Course Guide
     What's New

The following schematic illustrates the basic steps in event handling for a button "click":

The operating system detects the physical signal generated by the mouse click when the cursor resides over a button. The OS sends a message with data about the event to the peer component object in the AWT system of the JVM, which then checks for event listeners registered to receive events for that type of event occuring over a particular component.

There are different kinds of listeners for different kinds of events. A listener implements the interface for a particular kind of event . Here are some examples:

  • Button clicks - ActionListener
  • Mouse button clicks - MouseListener
  • Mouse movements - MouseMotionListener
  • Closing a frame - WindowListener

Note that these interfaces subclass the EventListener interface.

The button class includes the method addActionListener(ActionListener). It allows for objects that implement the ActionListener interface to add themselves to a button's list of objects to call when it is clicked. (Thus the ActionListener interface provides for a callback reference.)

The call is made by invoking the actionPerformed(ActionEvent ae) method of the ActionListener interface, which the classes will override with their own code.

The details of event generation are beyond this course but the following diagram shows roughly the steps taken by the component over which the event occurred. The DispatchEvent() and ProcessEvent() methods see that the registered listeners are called and passed the AWTEevent (or its subclass) object.

We see that a button event results in all of the ActionListener objects that are registered with that button getting their actionPerformed(ActionEvent ae) methods invoked. The ActionEvent ae object carries the information about the event such as what button generated it. The actionPerformed() method can use this info to identify the source of the event and decide what to do based on that information.

References and Web Resources

Latest update Nov. 1, 2004

           Tech
Histogram UI
  Demo 1
Probablity Distrib.
  Demo 2 Demo 3
RejectionMethod
Histogram Stats
  Demo 4
Exercises

           Physics
Sim & Randomness
Custom Prob. Dist.
   Demo 1
Histogram Dist.
   Demo 2
Monte Carlo
  Demo 3
Exercises

  Part I Part II Part III
Java Core 1  2  3  4  5  6  7  8  9  10  11  12 13 14 15 16 17
18 19 20
21
22 23 24
Supplements

1  2  3  4  5  6  7  8  9  10  11  12

Tech 1  2  3  4  5  6  7  8  9  10  11  12
Physics 1  2  3  4  5  6  7  8  9  10  11  12

Java is a trademark of Sun Microsystems, Inc.