Java Reference
In-Depth Information
Sample Run: Figure 12-13 shows a sample run of the applet with check boxes.
FIGURE 12-13 Welcome applet with check boxes
JRadioButton
Check boxes allow the user to select values from a given set of values. The program in the
previous section used two check boxes. The user could select or deselect one or both
check boxes. However, there are situations in which you want the user to make only one
selection from a set of values. For example, if the user needs to select the gender of a
person, the user selects either female or male, but not both. If you want the user to select
only one of the options presented, you use radio buttons. To make such selections
possible, Java provides the class JRadioButton .
Table 12-11 shows some of the constructors and methods of the class JRadioButton .
TABLE 12-11 Some Constructors and Methods of the class JRadioButton
public JRadioButton()
//Creates an initially unselected radio button
//with no label and no icon.
//Example: JRadioButton myJRadioButton = new JRadioButton();
//
1
2
myJRadioButton points to the radio button with no label
//
and no icon.
public JRadioButton(Icon icon)
//Creates an initially unselected radio button
//with the specified icon and no label.
//Example: JRadioButton myJRadioButton =
//
new JRadioButton(anIcon);
//
myJRadioButton points to the radio button with the
//
icon "anIcon".
 
 
 
Search WWH ::




Custom Search