Java Reference
In-Depth Information
fGreen = new JCheckBox ( " Green " );
fGreen.addItemListener (this);
add (fGreen);
fBlue = new JCheckBox ("Blue");
fBlue.addItemListener (this);
add (fBlue);
} // ctor
/**
*Anitem event from a checkbox comes here when
* the user clicks on one.
**/
public void itemStateChanged (ItemEvent evt) {
if (evt.getStateChange () == ItemEvent.SELECTED)
System.out.println ("SELECTED");
else
System.out.println ( " DESELECTED " );
int cr = (fRed.isSelected () ? 0xFF: 0);
int cg = (fGreen.isSelected ()? 0xFF: 0);
int cb = (fBlue.isSelected () ? 0xFF: 0);
fOutputPanel.setColor (cr,cg,cb);
} // itemStateChanged
} // class CheckBoxesPanel
7.3.2 JRadioButton
Radio buttons allow for situations where only one of several choices can be
accepted. You must add the particular set of radio buttons into a ButtonGroup ,
which enforces the exclusionary rule. Figure 7.5 shows UiTestApplet again,
this time for the case where the applet parameter specified the use of the
Figure 7.5 The JRadioButton component allows for the selection of only one
button in a set of buttons. With RadioButtonsPanel displayed by UITestApplet ,
the user selects one of three color components to create the background color for
the top panel.
 
Search WWH ::




Custom Search