Checkbox
Checkbox
Definition
A Check box may be control that is used to turn an option on or off.
It consists of a little box that will either contain a check or not .Checkboxes are
often used individually or as a part of a gaggle
Checkboxes are objects of the checkboxes.
creating a checkbox
Checkbox cb=new Checkbox(Label);
Class declaration
Public class Checkbox extends Component implements Itemselectable ,Accessible {
}
Constructor
1.Checkbox()
Creates a Checkbox whose label is initially blank . The state of the
Checkbox is unchecked.
2.Checkbox (String str)
Creates a Checkbox whose label is Specified by str. The State of
the
Checkbox is unchecked.
3. Checkbox( String str, Boolean on)
It allows you to line the initial State of the Checkbox . If one is
true, the checkbox is
initially Checked; Otherwise, it's cleared.
Methods
1.boolean get State( )
To retrieve the present State of a Checkbox.
2.Void Set State (boolean on)
To line its State, call Set States( )Here, If one is true, the
box is checked, If it 's false, the box is cleared.
3.String getLabel( )
You'll obtain the present a label related to a checkbox by
Calling
getlabel.
4. Void set Label (String Str)
To line the label, Call set Label( )The String passed in str
Example :
import java.awt.*;
public class CheckboxExample
{
CheckboxExample(){
Frame f= new Frame("Checkbox Example");
Checkbox checkbox1 = new Checkbox("C++");
checkbox1.setBounds(100,100, 50,50);
Checkbox checkbox2 = new Checkbox("Java",true);
checkbox2.setBounds(100,150,50,50);
f.add(checkbox1);
f.add(checkbox2);
f.setSize(400,400);
f.setLayout(null);
f.setVisible(true);
}
public static void main(String args[])
{
new CheckboxExample();
}