Java Reference
In-Depth Information
Figure 26. Code segment for Zoo.java
1.
public class ViewBehavior extends Behavior
2.
{
3.
private TransformGroup targetTG; private Transform3D rotation = new Transform3D();
4.
private double angle = 0.0; private float angley, anglex;
5.
private BoundingSphere bounds = new BoundingSphere(new Point3d(0f,0f,10f), 1.0);
6.
private BoundingSphere bounds2 = new BoundingSphere(new Point3d(0f,0f,1f), 1.0);
7.
private WakeupCriterion eventsCondition[] = new WakeupCriterion[4];
8.
private WakeupOr allEvents;
9.
10.
ViewBehavior(TransformGroup targetTG) this.targetTG = targetTG;
11.
12.
public void initialize()
13.
{
14.
eventsCondition[0] = new WakeupOnViewPlatformEntry(bounds);
15.
eventsCondition[1] = new WakeupOnViewPlatformExit(bounds);
16.
eventsCondition[2] = new WakeupOnViewPlatformEntry(bounds2);
17.
eventsCondition[3] = new WakeupOnViewPlatformExit(bounds2);
18.
allEvents = new WakeupOr(eventsCondition); wakeupOn(allEvents);
19.
}
20.
21. public void processStimulus(Enumeration criteria)
22.
{
23.
WakeupCriterion wakeup;
24.
while (criteria.hasMoreElements())
25.
{
26.
wakeup = (WakeupCriterion) criteria.nextElement();
27.
if (wakeup instanceof WakeupOnViewPlatformEntry)
28.
{
29.
if(((WakeupOnViewPlatformEntry)wakeup)==eventsCondition[0])
30.
System.out.println("WELCOME TO THE ZOO!");
31.
if(((WakeupOnViewPlatformEntry)wakeup)==eventsCondition[2])
32.
System.out.println("TIGERS ARE AN ENDANGERED SPECIES");
33.
}
34.
if (wakeup instanceof WakeupOnViewPlatformExit)
35.
{
36.
if(((WakeupOnViewPlatformExit)wakeup)==eventsCondition[1])
37.
System.out.println("DON'T FORGET TO LOOK AT THE TIGERS!");
38.
if(((WakeupOnViewPlatformExit)wakeup)==eventsCondition[3])
39.
System.out.println("ROAR!");
40.
}
41.
}
42.
this.wakeupOn(allEvents);
43.
}
44. }
for the platform. Whenever the ViewPlatform enter the first bound, a trigger event will
be generated and the message “WELCOME TO THE ZOO!” will be printed. On leaving
this bound, the message “DON'T FORGET TO LOOK AT THE TIGERS” will be printed.
Search WWH ::




Custom Search