Java Reference
In-Depth Information
Behavor criterion in making sure that different behaviors are applied appropriately to a
visual object.
Figure 22 shows how this criterion can be set and the supported method. Figures 23
and 24 present a simple example on its use. Specifically, Figure 23 shows the important
code segment for detecting some key strokes and changing the transform for a translational
movement of some objects, while Figure 24 gives the code for printing out appropriate
movement messages when the transform has been changed.
Line 7 in the code segment of Figure 23 initializes a behavior for the movement of the
objects. As indicated, the behavior will be woken up when a key is pressed. The associated
processStimulus method then carries out some key decoding and then changes the transform
Figure 24. Second code segment and result of TransformChange.java
1.
public ChangeBehavior(TransformGroup targetTG)
2.
{
3.
ourTG=targetTG;
4.
event= new WakeupOnTransformChange(ourTG);
5.
}
6.
7.
public void initialize()
8.
{
9.
System.out.println("Started!");
10.
this.wakeupOn(event);
11. }
12.
13. public void processStimulus(java.util.Enumeration criteria)
14. {
15.
WakeupCriterion wakeup;
16.
while (criteria.hasMoreElements())
17.
{
18.
wakeup = (WakeupCriterion) criteria.nextElement();
19.
if (wakeup instanceof WakeupOnTransformChange)
20.
{
21.
22.
System.out.println("You're moving "+direct);
23.
}
24.
this.wakeupOn(event);
25.
}
26. }
Search WWH ::




Custom Search