The source code of all examples is included in the JGameGrid distribution.
Check buttons are used to make a non-exclusive selection of a boolean value, e.g. to answer a yes-no question. They are common for setting-up application initial conditions. The GGCheckButton class is a special type of a button, therefore derived from GGButtonBase that subclasses Actor. The button appearance is a square of given size for the unchecked state with a diagonal cross for the checked state. An annotation text is placed to the right of the square. This is a somewhat restricted choice, but smarter check buttons are easily implemented using GGToogleButton. The corresponding actor of a check button is actually a rectangle with the height of the square and the length roughly twice the text length plus the square size. The square is positioned in the middle of the rectangle. The left side of the rectangle is transparent and the right side contains the text. Because the center of the actor's area is at the center of the square, several check buttons may be easily vertically aligned. For fine positioning the buttons in a GameGrid windows with a coarse grid, the location may be moved by a fixed pixel offset by using GameGrid.setLocationOffset(). Changes from the unchecked to the checked state and vice versa are reported by an event callback buttonChecked() defined in the GGCheckButtonListener interface. As with the GGButton class, events are inserted into a Fifo queue and the callback method is invoked by the separate button event thread. In the following example there are two check buttons to run/pause the program and to modify the simulation period. The default text and background colors of GGCheckButton are used, because the playground's background is white. The speed check button is initially checked by setting the boolean constructor parameter.
Execute the program locally using WebStart.
Ex16: Radio Button Actors Normally radio buttons are used for an exclusive selection of a certain number of boolean values, e.g. to select one of several proposals. To achieve this, the radio buttons are grouped together in a GGRadioButtonGroup that is responsible to allow one and only one button to be selected. The GGRadioButton class is a special type of a GGButton, thus derived from GGButtonBase that subclasses Actor. The button appearance is a circle of given size for the deselected state with a center spot for the checked state. An annotation text is placed to the right of the circle. Like for GGCheckButton this is a somewhat restricted choice, but smart radio buttons are easily implemented using GGToogleButton. The layout of the corresponding actor is the same as for check buttons. Ex15 gives more information if needed. Changes from the deselected to the selected state and vice versa are reported by an event callback buttonSelected() defined in the GGRadioButtonListener interface. As with the GGButton class, events are inserted in a Fifo queue and the callback method is invoked by a separate button event thread. Adding a radio button into more than one button radio group is not allowed. In the following example the sprite image of a car actor is changed at run-time by clicking one of the three radio buttons. Because the GGRadioButtonListener is registered in the GGRadioButtonGroup, only 'select' events are reported, so the parameter selected is always true. The GGRadioButtonGroup constructor accepts any number of GGRadioButton references because it uses ellipsis (variable length argument list). To insert a button into a button group that is already constructed, GGRadioButtonGroup.add() may be used that also supports ellipsis.
Execute the program locally using WebStart.
| ||||||||||