|
AnalogClock
AnalogClock ist eine GUI-Komponente zur einfachen grafischen Darstellung einer analogen Uhr mit Stunden-, Minuten- und Sekundenzeiger. Die AnalogClock ist frei skalierbar. Da sie aber nicht animiert ist, muss diese Aufgabe von der Anwendung übernommen werden. Dazu kann die Methode setValue aufgerufen werden, womit die Zeigerposition aktualisiert wird.
|
Bild 5 zeigt einen Screenshot der JControl-Anwendung VoleAnalogClockExample
. Der Quelltext ist unten aufgelistet. Das Beispielprogramm demonstriert die Befehle zur Instantiierung einer AnalogClock
und zeigt, wie die Uhrzeit durch eine einfache Schleife fortlaufend aktualisiert werden kann.
Bild 5: Das 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