AWT Components -- Checkbox
Checkboxes are on-off toggles implemented as
- Checkbox red = new Checkbox("Red");
- Checkbox green = new Checkbox("Green");
- Checkbox blue = new Checkbox("Blue",null, true);
- add(red); add(green); add(blue);
The first two are initially set to "false" as the optional third argument is not given. The last one is initially set to "true".
The state of a checkbox, i.e. whether it is checked, is given by a boolean result of the method, getState:
- if (red.getState()) . . .;
If a user clicks a Checkbox, an ItemEvent is generated. The listener must implement ItemListener with the one method itemStateChanged (ItemEvent e).