Java simple theory notes for AWT controls part2
CheckBox
A check box is a graphical component that can be in either an "on" (true) or "off" (false) state. Clicking on a check box changes its state from "on" to "off," or from "off" to "on."
In other words, the checkbox control is used to select or deselect different options.These control also have a label associated with them which describe the option of the checkbox.
How to create a label?
syntax for creating labels:
Checkbox cbox1=new Checkbox();
Checkbox cbox2=new Checkbox(String);
Checkbox cbox3=new Checkbox(String,boolean);
Here cbox1,cbox2,cbox3 are the object name, the programmer can give the desired name as the object name.
Given above are three types of constructor for the checkbox
The first one creates a blank default checkbox.The label for checkbox can
be set using the setLabel() method
The second constructor creates a checkbox with the specified label.
The last one creates a checkbox that can be set as checked or unchecked.
The state of a checkbox may change at any instant of time.
Therefore a method called setState(boolean) is used to change the state of the checkbox.
The method getState() is used to get the state of the checkbox.
checkboxGroup for creating radio button:
A group of checkboxes under one group can be created and then one of these can be selected using the control checkboxGroup.That is, at any time only one checkbox can be selected.These checkboxes are known as radio buttons.
Comments
Post a Comment