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
1 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);
2 The first two are initially set to "false" as the optional third argument is not given. The last one is initially set to "true".
3 The state of a checkbox, i.e. whether it is checked, is given by a boolean result of the method, getState:
  • if (red.getState()) . . .;
4 If a user clicks a Checkbox, an ItemEvent is generated. The listener must implement ItemListener with the one method itemStateChanged (ItemEvent e).
5 Red
6 Green
7 Blue

in Table To:


© 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