Basic HTML version of Foils prepared Sept 21 1998

Foil 37 AWT Components -- Checkbox

From Java Tutorial 98- 3: Graphics and the Abstract Windowing Toolkit NAVO Tutorial -- Sept 23 1998. by Geoffrey C. Fox, Nancy McCracken

Checkboxes for Foil 37
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).
Red
Green
Blue



© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sat Nov 28 1998