Java Reference
In-Depth Information
The main point of interest in this program is the item event handler, itemStateChanged(
) . It performs two functions. First, it reports whether the check box has been selected or
cleared. Second, it displays all selected check boxes. It begins by obtaining a reference to
the check box that generated the ItemEvent , as shown here:
The cast to JCheckBox is necessary because getItem( ) returns a reference of type Ob-
ject . Next, itemStateChanged( ) calls isSelected( ) on cb to determine the current state of
the check box. If isSelected( ) returns true, it means that the user selected the check box.
Otherwise, the check box was cleared. It then sets the jlabChanged label to reflect what
happened.
Search WWH ::




Custom Search