Basic HTML version of Foils prepared 13 October 97

Foil 37 AWT Components -- Checkbox

From Java Tutorial, July 1, 1996 CSC499(JSU) CPS406/606 -- Fall Semester 97. by Nancy J. McCracken,Geoffrey C. Fox

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

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 Wed Apr 1 1998