AnalogClock

AnalogClock is a GUI component to to simply draw an analogue clock with hands for hours, minutes and seconds. The AnalogClock is freeley scaleable. Since it isn't animated, this task has to be inherited by the application. The method setValue can be invoked for that purpose, whereby the hands' positions are updated.

Figure 5 shows a screenshot of the JControl application VoleAnalogClockExample. Its source code is listet below. The program example demonstrates the commands to instantiate an AnalogClock und shows how the time can be updated by a simple continuous loop.

Figure 5: The VoleAnalogClockExample

1    import jcontrol.lang.ThreadExt;
2    import jcontrol.system.Time;
3    import jcontrol.ui.vole.Border;
4    import jcontrol.ui.vole.Frame;
5    import jcontrol.ui.vole.meter.AnalogClock;
6    
7    /**
8     * <p>This example demonstrates how to use the
9     * component AnalogClock within the GUI framework
10     * JControl/Vole.</p>
11     *
12     * <p>(C) DOMOLOGIC Home Automation GmbH 2003-2005</p>
13     */
14    public class VoleAnalogClockExample extends Frame {
15     
16      /**
17       * Create and continuosly update an AnalogClock
18       */
19      public VoleAnalogClockExample() {
20        // create a new AnalogClock
21        AnalogClock ac = new AnalogClock(35, 7, 26, true);
22        this.add(ac);
23       
24        // add a border
25        this.add(new Border("Analog Clock", 26, 0, 70, 64));
26       
27        // make us visible
28        show();
29       
30        // update the AnalogClock's time once a second
31        for (;;) {
32          Time t = new Time();
33          ac.setValue(t.hour, t.minute, t.second);
34          try {
35            ThreadExt.sleep(1000);
36          } catch (InterruptedException e) {}
37        }     
38      }
39    
40      /**
41       * Instantiate the example
42       */
43      public static void main(String[] args) {
44        new VoleAnalogClockExample();
45      }
46    }
Listing 5: VoleAnalogClockExample.java