Frame
Die Klasse jcontrol.ui.vole.Frame
zeichnet für die Tastaturabfrage, das Event-Handling und das Focus-Management verantwortlich. Sie erweitert außerdem die Klasse jcontrol.ui.vole.Container
und besitzt alle ihre Fähigkeiten. Einem Frame können Components und Container hinzugefügt werden. Der folgende Quelltext zeigt eine einfache Anwendung, die ein Label
-Component und zwei Button
-Components darstellt.
Bild 2: Screenshot des VoleExampleBase-Programms
1 | import jcontrol.ui.vole.Button; |
2 | import jcontrol.ui.vole.Frame; |
3 | import jcontrol.ui.vole.Label; |
4 | |
5 | /** |
6 | * <p>This example demonstrates how to implement JControl |
7 | * applications with a graphical user interface |
8 | * using the GUI framework JControl/Vole.</p> |
9 | * |
10 | * <p>(C) DOMOLOGIC Home Automation GmbH 2003-2005</p> |
11 | */ |
12 | public class VoleExampleBase extends Frame { |
13 | |
14 | Button b1, b2; |
15 | Label l; |
16 | |
17 | /** |
18 | * Create and show a label and two buttons. |
19 | */ |
20 | public VoleExampleBase() { |
21 | // create some components |
22 | l = new Label("Welcome to Vole!", 0, 5, 128, 10, |
23 | Label.ALIGN_CENTER); |
24 | b1 = new Button("Button 1", 8,20,50,12); |
25 | b2 = new Button("Button 2", 62,20,50,12); |
26 | |
27 | // add the components to the frame |
28 | this.add(l); |
29 | this.add(b1); |
30 | this.add(b2); |
31 | |
32 | // make the frame visible |
33 | show(); |
34 | } |
35 | |
36 | public static void main(String[] args) { |
37 | new VoleExampleBase(); |
38 | } |
39 | } |
Listing 1: VoleExampleBase.java
Bild 2 zeigt einen Screenshot von obigem Beispielprogramm. Wenn Sie den Quelltext dieses Beispiels herunterladen, in ein neues JControl/IDE-Projekt einfügen und dann den Simulator starten, sehen Sie das GUI-Framework JControl/Vole in Aktion. Die Klasse Frame
sorgt automatisch für eine kontinuierliche Abfrage der Tastatur, durch Bewegen des Tasters am JControl-Gerät können Sie den Eingabefokus zwischen den beiden Buttons hin- und herschalten. Da wir in dem Beispielprogramm jedoch keinen ActionListener
für die Buttons installiert haben, empfängt das Programm keine ActionEvents
und kann somit auch nicht auf das Betätigen eines Buttons reagieren. Wie Events verarbeitet werden, können Sie in Kapitel 4 dieses Tutorials nachlesen (Event-Handling).