To simplify user interaction and make data entry easier, you can use java controls. Controls are components, such as buttons, labels and text boxes, that can be added to containers like frames, panels and applets. The Java.awt package provides an integrated set of classes to manage user interface components.
CheckboxGroup is also called like a radio button or exclusive check boxes. To organize several Checkboxes into a group so that only one can be selected at a time, a CheckboxGroup object is created with the statement such as follows:
CheckboxGroup radio = new CheckboxGroup ();
The CheckboxGroup keeps track of all the check boxes in its group. We have to use this object as an extra argument to the Checkbox constructor.
Checkbox (String, CheckboxGroup, Boolean) creates a checkbox labeled with the given string that belongs to the CheckboxGroup indicated in the second argument. The last argument equals true if box is checked, false otherwise.
The following is an applet to enable you to select one of the ways to connect to the Internet.
Public class ChkGroup extends java.applet.Applet { CheckboxGroup cbgr = new CheckboxGroup(); Checkbox c1 = new Checkbox (“America Online”, cbgr, false); Checkbox c2 = new Checkbox (“MSN”, cbgr, false); Checkbox c3 = new Checkbox (“NetZero”, cbgr, false); Checkbox c4 = new Checkbox (“EarthLink”, cbgr, false); Checkbox c5 = new Checkbox (“Bellsouth DSL”, cbgr, true);
Public void init(){ add(c1); add(c2); add(c3); add(c4); add(c5); } }
The setCurrent(checkbox) method can be used to make the set of currently selected check boxes in the group. There is also a getCurrent() method, which returns the currently selected checkbox.