Frame
The class jcontrol.ui.wombat.Frame
is responsible for keyboard queries, event handling, focus management and last but not least painting of components. The following source code shows a simple application using JControl/Wombat, displaying one Label-
component and two Button-
components.
Figure 2: Screenshot of the program WombatExampleBase
1 | import jcontrol.ui.wombat.Button; |
2 | import jcontrol.ui.wombat.Container; |
3 | import jcontrol.ui.wombat.Frame; |
4 | import jcontrol.ui.wombat.Label; |
5 | |
6 | /** |
7 | * <p>This example demonstrates how to implement JControl |
8 | * applications with a graphical user interface |
9 | * using the GUI framework JControl/Wombat.</p> |
10 | * |
11 | * <p>(C) DOMOLOGIC Home Automation GmbH 2003-2005</p> |
12 | */ |
13 | public class WombatExampleBase extends Frame { |
14 | |
15 | Button b1, b2; |
16 | Label l; |
17 | |
18 | /** |
19 | * Create and show a label and two buttons. |
20 | */ |
21 | public WombatExampleBase() { |
22 | // create some components |
23 | l = new Label("Welcome to Wombat!", 0, 5, 128, 10, Label.STYLE_ALIGN_CENTER); |
24 | b1 = new Button("Button 1", 8,20,50,12); |
25 | b2 = new Button("Button 2", 62,20,50,12); |
26 | |
27 | // creates a new componaint container |
28 | Container c = new Container(); |
29 | |
30 | // add the components to the container |
31 | c.add(l); |
32 | c.add(b1); |
33 | c.add(b2); |
34 | |
35 | // add container to this frame |
36 | setContent(c); |
37 | |
38 | // make the frame visible |
39 | setVisible(true); |
40 | } |
41 | |
42 | public static void main(String[] args) { |
43 | new WombatExampleBase(); |
44 | } |
45 | } |
Listing 1: WombatExampleBase.java
Figure 2 shows a screenshot of the example program shown above. You may download the examples' source code, add it to new JControl/IDE project, start the simulator and see the features of JControl/Wombat action. The class Frame
continously queries the keyboard. Using the pushbutton of a JControl device may toggle the focus between the two buttons. Since our example program doesn't install an ActionListener
for the buttons, the program does not receive any ActionEvents
and therefore it can't respond to a button being pressed. The event handling will be discussed in chapter 4 of this tutorial.