Method | Description |
MultiImageMenu(int x, int y, int width, int height, int horizontalCount, int verticalCount, int style) | Creates a new MultiImageMenu with specified bounds. The parameters horizontalCount and verticalCount specify the number of rows and columns. The style parameter provides two constant values STYLE_SHOW_BORDER and STYLE_NONE . |
setImageItems(Resource[] imageItems) | Sets the specified list of image resources to the the MultiImageMenu. The array may contain null values to define blanks in the MultiImageMenu. |
setTextItems(String[] textItems) | Sets the specified list of strings to the the MultiImageMenu. The array may contain null values to define blanks in the MultiImageMenu. |
int addMenuItem(String item) | Adds an entry into the MultiImageMenu. If there is an image resource available matching the specified string the icon will be shown. Otherwise, the string itself will be shown. The returned value specifies the index of the item. |
int insertMenuItem(String item, int index) | Inserts an entry into the MultiImageMenu at the specified position. Any existing entry at this position will be discarded. If there is an image resource available matching the specified string the icon will be shown. Otherwise, the string itself will be shown. The returned value specifies the index of the item. |
int getFirstFreeIndex() | Returns the first index in the MultiImageMenu that is empty, i.e. does not contain any item. |
setTouchMargin(int margin) | Specifies the size of the non-touchable area around the menu items. Default value is 5. |
A short source code shall be given at the conclusion of this section, that demonstrates the usage of the GUI components ComboBox
, NumberChooser
, and MultiImageMenu
. It is available in the project WombatSelectorExample
in the installation directory of your JControl/IDE under "demos/cobra5329/WombatTutorial/WombatSelectorExample"
(on Windows "C:\Program Files\JControl\demos\cobra5329\WombatTutorial\WombatSelectorExample"
). Figure 2 shows a screenshot of the running program.
1 | /** |
2 | * <p>This example demonstrates how to use the |
3 | * components ComboBox, NumberChooser and MultiImageMenu within |
4 | * the GUI framework JControl/Wombat.</p> |
5 | * |
6 | * <p>(C) DOMOLOGIC Home Automation GmbH 2007</p> |
7 | */ |
8 | import jcontrol.ui.wombat.Frame; |
9 | import jcontrol.ui.wombat.Container; |
10 | import jcontrol.ui.wombat.event.ActionListener; |
11 | import jcontrol.ui.wombat.Border; |
12 | import jcontrol.ui.wombat.ComboBox; |
13 | import jcontrol.ui.wombat.NumberChooser; |
14 | import jcontrol.ui.wombat.menu.MultiImageMenu; |
15 | import jcontrol.io.Resource; |
16 | import java.io.IOException; |
17 | import jcontrol.graphics.Color; |
18 | import jcontrol.ui.wombat.event.ActionEvent; |
19 | |
20 | public class WombatSelectorExample extends Frame implements ActionListener { |
21 | |
22 | /** |
23 | * Constructor WombatComboNumberExample |
24 | */ |
25 | public WombatSelectorExample() { |
26 | // create a container for the content of this frame |
27 | Container content = new Container(); |
28 | |
29 | // create borders and add them to the content |
30 | Border border1 = new Border("ComboBox", 60, 40, 180, 40, |
31 | Border.STYLE_ETCHED_BORDER); |
32 | content.add(border1); |
33 | Border border2 = new Border("NumberChooser", 60, 80, 180, 40, |
34 | Border.STYLE_ETCHED_BORDER); |
35 | content.add(border2); |
36 | Border border3 = new Border("MultiImageMenu", 60, 120, 180, 70, |
37 | Border.STYLE_ETCHED_BORDER); |
38 | content.add(border3); |
39 | |
40 | /* create all components |
41 | add them to the content |
42 | and define an actionlistener for each component */ |
43 | |
44 | // ComboBox |
45 | ComboBox comboBox = new ComboBox(new String[]{ |
46 | "Entry 1", "Entry 2", "Entry 3"}, 110, 56, 80); |
47 | content.add(comboBox); |
48 | comboBox.setActionListener(this); |
49 | |
50 | // NumberChooser |
51 | NumberChooser numberChooserDay = new NumberChooser(112, 96, 1, 31); |
52 | numberChooserDay.setValue(1); |
53 | content.add(numberChooserDay); |
54 | numberChooserDay.setActionListener(this); |
55 | NumberChooser numberChooserMonth = new NumberChooser(136, 96, 1, 12); |
56 | numberChooserMonth.setValue(1); |
57 | content.add(numberChooserMonth); |
58 | numberChooserMonth.setActionListener(this); |
59 | NumberChooser numberChooserYear = new NumberChooser(160, 96, 2000, 2100); |
60 | numberChooserYear.setValue(1); |
61 | content.add(numberChooserYear); |
62 | numberChooserYear.setActionListener(this); |
63 | |
64 | // MultiImageMenu |
65 | MultiImageMenu multiImageMenu = new MultiImageMenu(70, 136, 160, 44, |
66 | 3, 1, MultiImageMenu.STYLE_SHOW_BORDER); |
67 | try { |
68 | multiImageMenu.setImageItems(new Resource[]{ |
69 | new Resource("item1.jcif"), |
70 | new Resource("item2.jcif"), |
71 | new Resource("item3.jcif")}); |
72 | } catch(IOException ioe) {} |
73 | multiImageMenu.setBackgroundColor(Color.WHITE); |
74 | content.add(multiImageMenu); |
75 | multiImageMenu.setActionListener(this); |
76 | |
77 | // set the content to this frame |
78 | setContent(content); |
79 | // finally, make the frame visible |
80 | setVisible(true); |
81 | } |
82 | |
83 | /** |
84 | * This method is called every time any component declared above |
85 | * fires an action event. |
86 | * |
87 | * @param e the ActionEvent |
88 | */ |
89 | public void onActionEvent(ActionEvent e) { |
90 | // add some code if you want to |
91 | } |
92 | |
93 | /** |
94 | * The main method. |
95 | * |
96 | * @param args |
97 | * The main arguments |
98 | */ |
99 | public static void main(String[] args) { |
100 | new WombatSelectorExample(); |
101 | } |
102 | } |