|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--ibm.techexplorer.util.EventObject | +--ibm.techexplorer.awt.AWTEvent
ibm.techexplorer.awt.AWTEvent
The techexplorer AWT event hierarchy provides the organization for several types of events that techexplorer instances can trigger. techexplorer events follow the Java 1.1 event model used by the Java AWT and Java Beans. Although the techexplorer event model is similar to that of Java 1.1, it can still be used in conjunction with applets the make use of Java 1.0 events. In fact, for purposes of Java 1.0 compatibility, techexplorer events do not subclass from Java 1.1 event classes. As a consequence, the techexplorer Java library provides all of the required classes for application development. Note that although techexplorer AWT events are based on the Java 1.1 AWT event model, several methods and attributes found in the Java 1.1 AWT classes are not used. In this sense, the techexplorer AWT event model can be viewed as a subset of the Java 1.1 AWT model.
Subclasses of the AWTEvent
class provide event specific information. For example the
ibm.techexplorer.awt.event.InputEvent
AWTEvent subclass adds information such as pressed modifier keys. The
ibm.techexplorer.awt.event.MouseEvent
and
ibm.techexplorer.awt.event.KeyEven
t
subclasses of InputEvent contain information about the mouse and keyboard respectively.
Events are generated by event sources. In our context, techexplorer is an event source that can fire one
or more different types of events. For each type of event that techexplorer fires, techexplorer maintains
a list of event listeners. One or more listeners can register to be notified about techexplorer events. An event
listener registers with techexplorer by using the registration methods provided in
ibm.techexplorer.techexplorer
This notification model is similar to the Observer design pattern [Gamma E.,Helm R.,Johnson R.,Vlissides J. Design Patterns, Elements of Reusable Object-Oriented Software, Addison-Wesley Reading Massachusetts, 1994]. This pattern defines a one to many dependancy between objects so that when one object changes state, all of its dependents are notified and updated automatically.
Event handlers can be instances of any class that implement an event listener interface. Each interface specifies the
methods that a listener of a particular event type must implement. For example, the
ibm.techexplorer.awt.event.FocusListener
contains
two methods, namely focusGained
and focusLost
. When a techexplorer document receives the focus, the focusGained
method will be called for each registered listener. Consequently, when a techexplorer document looses focus,
the focusLos
t method will be invoked. All methods defined in a listener interface must be implemented, even if
a particular Java applet only requires one method in the interface. For those events not required by a Java
applet simply provide empty bodies for the reaming listener methods. To alleviate the resulting collection of empty
method bodies, the techexplorer AWT provides adapter classes for each listener interface. The
techexplorer adaptor classes provides empty implementations of all of the corresponding interface
methods. To use an adapter, subclass the appropriate adaptor class and provide methods for the events your applet requires.
Current Restriction: Note that although the techexplorer AWT event model allows a Java applet to handle events, the generation of techexplorer events from Java is not permitted in this version.
Java applets can enable or disable the flow of events to a particular techexplorer instance. techexplorer maintains an event mask for keeping track of the enabled events. Java applets can use theibm.techexplorer.techexplorer
enableEvents()
and disableEvents()
methods to allow and disallow event flow to
techexplorer respectively. Note that this only effects the event flow to a particular techexplorer instance
and not the event flow to techexplorer listeners. This is often used by Java applets to disable default and
user defined context menus, hypermedia links, and text selection to name a few.
Most events are delivered first to the techexplorer instance and then to any registered listeners. The only
exception is the ibm.techexplorer.plugin.InstanceEvent
.
Since this event notifies a registered listener of techexplorer life cycle changes, techexplorer responds to the
event after the applet has been notified.
Every Java applet that makes use of techexplorer events contain four similar
pieces of code. For example, let's look at four code fragments from the
TEMessageListener
applet:
import ibm.techexplorer.techexplorer; import ibm.techexplorer.awt.AWTEvent; import ibm.techexplorer.awt.event.MouseEvent; import ibm.techexplorer.awt.event.MouseListener;
public class TEMessageListener extends Applet implements MouseListener {
Plugin.addMouseListener( (MouseListener)this );
public void mouseClicked( MouseEvent e ) { } public void mouseEntered( MouseEvent e ) { } public void mouseExited ( MouseEvent e ) { } public void mousePressed( MouseEvent e ) { } public void mouseRelease( MouseEvent e ) { }
Press here to try out the TEMessageListener
applet.
Click here for the whole program. Note that since some browsers do not support
Java 1.1, the TEMessageListener
applet is Java 1.0 compliant.
FocusEvent
,
InputEvent
,
KeyEvent
,
MouseEvent
Field Summary | |
static int |
FOCUS_EVENT_MASK
The event mask for selecting focus events. |
static int |
KEY_EVENT_MASK
The event mask for selecting key events. |
static int |
MOUSE_EVENT_MASK
The event mask for selecting mouse events. |
static int |
MOUSE_MOTION_EVENT_MASK
The event mask for selecting mouse motion events. |
Fields inherited from class ibm.techexplorer.util.EventObject |
documentName,
id,
listenerClass,
objectName,
source |
Constructor Summary | |
AWTEvent()
|
Methods inherited from class ibm.techexplorer.util.EventObject |
getDocumentName,
getID,
getListenerClass,
getObjectName,
getSource |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
public static final int FOCUS_EVENT_MASK
public static final int KEY_EVENT_MASK
public static final int MOUSE_EVENT_MASK
public static final int MOUSE_MOTION_EVENT_MASK
Constructor Detail |
public AWTEvent()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |