- Forward


Custom Events
in Java


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

Overview
Back SMYC Forward
  • An Observation:
    • We sometimes want to add "custom" events to a graphical user interface
  • One Approach:
    • Add functionality to an existing component so that it responds to a "normal" event and generates a "custome" event
The Basics
Back SMYC Forward
  • AWT:
    • Use the AWTEventMulticaster class
  • Swing:
    • Use the EventListenerList class
An Example
Back SMYC Forward
  • A ColorButton that can be used to select a Color
  • A ColorEvent that can be used to inform objects of Color changes
  • A ColorListener interface
An Example (cont.)
Back SMYC Forward

ColorEvent

javaexamples/gui/ColorEvent.java
 
An Example (cont.)
Back SMYC Forward

ColorListener

javaexamples/gui/ColorListener.java
 
An Example (cont.)
Back SMYC Forward

ColorButton

javaexamples/gui/ColorButton.java
 
An Example (cont.)
Back SMYC Forward

An Application

javaexamples/gui/ColorButtonDriver.java
 
There's Always More to Learn
Back -