Java Reference
In-Depth Information
the ViewingPlatform region after the change and will result in a WakeupOnDeactivation
trigger after the current invocation of the processStimulus method has been completed.
The completion of the current invocation of processStimulus requires the checking of the
logical triggering status of the DeActivation criterion and then printing this out as a system
message. Since the running of the current processStimulus method is due to a WakeupO-
nActivation trigger, the output is of course false in nature. After printing this message, a
new wakeup trigger condition, which is based on WakeupOnDeactivation, is set.
After finishing the current processStimulus method and with the scheduling region
changed to be non-overlapping with the ViewingPlatform, a new trigger for WakeupOn-
Deactivation will be generated. The same processStimulus method will be invoked by the
system to deal with this trigger, and it is easy to see that the status message printed out
will now be true.
It is worthwhile to note that the setting of a new wakeup trigger condition, which is based
on WakeupOnDeactivation, is crucial. Without this, the processStimulus method will not be
invoked to deal with the WakeupOnDeactivation wakeup criterion. Also, as illustrated in
the code segment and the straightforward task involved in this simple example, it is easy to
make mistakes and difficult to debug programs involving complicated behavior. In general,
careful planning in the setting up of appropriate wakeup trigger conditions is essential to
ensure that objects in the Java 3D world behave in accordance with expectation.
keyboard and mouse events
The most common events that need to be dealt with in any Java 3D program are perhaps
those corresponding to changes in mouse and keyboard status, which result in Wake-
upOnAWTEvent (Geroimenko & Geroimenko, 2000). The usage of the latter and the
common associated AWT events are presented in Figure 8.
The code segment in Figure 9 shows how key strokes can be captured and processed
through WakeupOnAWTEvent. Lines 4 to 6 define the keys that will give rise to a trigger
for the behavior. Lines 21 to 27 correspond to the initialization method, which sets up the
initial trigger condition. Lines 29 to 43 give the processStimulus method, which will be
invoked by the system when the specified events have happened. Note that in this example,
the processStimulus method will simply decode the key that have been pressed, and then
pass this to a keyPressed method for relevant processing.
Figures 10 and 11 present an example for the processing of mouse events instead of
key strokes. The code is similar to that in Figure 9 for key strokes. Note that the method
MouseEvent is called after decoding the type of mouse movement or mouse button pressed
(Vormoor, 2001). Also, the method is supplied with an integer argument that identifies the
movement or button.
Search WWH ::

Custom Search