Java Reference
In-Depth Information
Figure 20. Code segment for SimpleElapsedFrames.java
1.
public class SimpleElapsedFrames extends Applet
2.
{
3.
private WakeupCriterion events[] = new WakeupCriterion[2];
4.
private WakeupOr allEvents;
5.
6.
public class SimpleFrames extends Behavior
7.
{
8.
private TransformGroup targetTG;
9.
10.
SimpleFrames (TransformGroup targetTG)
11.
{
12.
this.targetTG = targetTG;
13.
}
14.
15.
public void initialize()
16.
{
17.
events[0]=new WakeupOnAWTEvent(MouseEvent.MOUSE_PRESSED);
18.
events[1]=new WakeupOnElapsedFrames(100);
19.
allEvents=new WakeupOr(events);
20.
wakeupOn(allEvents);
21.
}
22.
23.
public void processStimulus(Enumeration criteria)
24.
{
25.
WakeupCriterion wakeup;
26.
while(criteria.hasMoreElements())
27.
{
28.
wakeup = (WakeupCriterion) criteria.nextElement();
29.
if(wakeup instanceof WakeupOnAWTEvent)
30.
System.out.println("MOUSE_CLICK");
31.
else
32.
System.out.println("100 FRAMES HAVE ELAPSED");
33.
}
34.
this.wakeupOn(allEvents);
35.
}
36. }
milliseconds or 1 second. The passing of 1 second will lead to a triggering of the same
processStimulus method to update the clock hands, giving the visual effect of a ticking
clock.
Search WWH ::




Custom Search