Java GUI Event Handling
Java and event handling: How events are passed to user interface components, how to create event handlers, and more
By Todd Sundsted
Summary
Here’s the rundown on event handling as implemented by the abstract windowing toolkit (AWT). This article describes the Event class and explains how the Java run-time system passes events to the components that make up a user interface. It also explains how to create event handlers either by redefining the handleEvent() method in a newly derived class, or by redefining one of its helper methods.
HTML Article: http://www.javaworld.com/javaworld/jw-08-1996/jw-08-event.html
Commentary
- Event driven messaging instead of big loop polling
- Event dispatching classes generate Event objects that descibe details about an event
- Event handling can be done from within the object who dispatched the event or the event object can be propagted to a higher object in the hierarchy.
- It looks like AS3/Flex has made this a core language feature with ‘event bubbling’. In Java, this is featured only in the AWT.
GUI Dynamics - Lecture 24 - CS211 Spring 2006
by Cornell University Computer Science Department
PDF of PowerPoint
http://www.cs.cornell.edu/courses/cs211/2006sp/Lectures/…
Homepage
http://www.cs.cornell.edu/courses/cs211/
Summary
Event listeners can be implemented in 1 of 3 ways:
Listener is defined as a method of a class (personal prefered method)
- a class has one behavior of setting up a listener to an event
- that same class has another behavior of handling events
Listener is defined as an Inner Class (Java Only)
- Inside the class that will perform an addEventListener(), that object has an inner class definition.
- When the addEventListener is performed, an instance of the inner class is created where it is passed into addEventListener()
- ActionScript to my knowledge does not have inner classes. Alternative: Can use mx.utils.delegate
Listener is defined as an Anonymous Class/Object directly as a parameter of addEventListener()
- function object is defined inside the arguments for addEventListener().
- great for small simple tasks but bad cause it’s hardcoding implementation.




