|
01 package examples.timer;
02
03
04 import fang.*;
05
06
07 /**makes a timer appear on the screen
08 * @author Jam Jenkins
09 */
10 public class TimerLoop extends Game
11 {
12 /**the time sprite*/
13 private StringSprite time;
14
15 /**makes the timer sprite, adds it to
16 * the screen and starts the alarm going
17 * off every second
18 */
19 public void setup()
20 {
21 makeSprites();
22 addSprites();
23 setHelp("resources/TimerLoopHelp.txt");
24 schedule(new TimerUpdate(), 1);
25 }
26
27 /**makes a string sprite to represent
28 * the time and starts it a 0.
29 */
30 private void makeSprites()
31 {
32 time=new StringSprite("0", true);
33 time.setHeight(0.5);
34 time.setLocation(0.5, 0.5);
35 }
36
37 /**adds the time sprite to the canvas*/
38 private void addSprites()
39 {
40 addSprite(time);
41 }
42
43 /**updates the time sprite to display
44 * the current time in seconds
45 * @author Jam Jenkins
46 */
47 private class TimerUpdate extends TimedAction
48 {
49 public void act()
50 {
51 time.setText(""+(int)getTime());
52 schedule(this, 1);
53 }
54 }
55
56 public static void main(String[] argv)
57 {
58 new TimerLoop().runAsApplication();
59 }
60 }
|