Java Reference
In-Depth Information
Figure 21. Code segment and result of WakeupOnElapsedTimeClock.java
1.
aHand SecHand, MinHand, HourHand;
2.
Point3f coor[] = new Point3f[120]; // contains coordinates to draw the clock
3.
Point3f coorHand[][] = new Point3f[3][60]; // 3 subarray contains coordinates to draw the 3 hands
4.
5.
public class SimpleBehavior extends Behavior
6.
{
7.
private TransformGroup targetTG;
8.
SimpleBehavior(TransformGroup TG) this.targetTG = TG;
9.
10.
public void initialize() this.wakeupOn(new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED));
11.
12.
public void processStimulus(Enumeration criteria)
13.
{
14.
Date timenow = new Date(); // get current time
15.
int sec, min, hour;
16.
sec = timenow.getSeconds();
17.
min = timenow.getMinutes();
18.
hour = timenow.getHours()%12;
19.
SecHand.setPos(sec, 0); //reset three hands
20.
MinHand.setPos(min, 1);
21.
HourHand.setPos(hour*5+min/12, 2);
22.
23.
this.wakeupOn(new WakeupOnElapsedTime(1000)); // set the WakeupCriterion for 1 sec
24.
}
25. }
events due to chanGes In posItIons and
transforms
Changes in the positions and the transform of objects in the 3D universe can be detected
through the use of the WakeupOnTransformChange criterion, which will give rise to a
trigger event for a behavior when the TransformGroup attached to it is changed. From a
certain point of view, it provides another way for the implementation of WakeupOnPost-
Search WWH ::




Custom Search