java.awt.Checkbox

A checkbox is a component that represents a boolean state. We've already seen checkboxes in action in our LabelTest applet shown in “LabelTest Applet”.

Checkboxes fire item events whenever they are checked or unchecked. In order to react to a checkbox being checked or unchecked, an item listener is added to the checkbox. When the checkbox fires an item event, the item listener's itemStateChanged method is invoked and passed an instance of ItemEvent.

Since checkboxes often exist in mutually exclusive groups, they can be added to a java.awt.CheckboxGroup, which ensures that only one checkbox in the group is checked at any given time. Note that a CheckboxGroup is not a component and therefore cannot be added to a container. As ...

Get Graphic Java™ 1.2, Volume I: AWT, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.