The Checkbox class is used to create a labelled check box. It has two parts a caption and state. The caption is text that represents the label of the control and the state is the boolean value(true/false).
By default the state is false which means the check box is unchecked.
Constructors:
Checkbox(String s)
Checkbox(String s,Initial state )
Methods:
getState() - returns the current state of the check box.
setState(boolean state) - It is used to set the state of check box.
Example:
import java.applet.*;
import java.awt.*;
public class CheckboxDemo extends Applet
{
public void init()
{
setLayout(new GridLayout(3, 1));
Checkbox c1=new Checkbox("Tamil", true);
Checkbox c2=new Checkbox("English");
Checkbox c3=new Checkbox("Maths");
add(c1);
add(c2);
add(c3);
}
}
/*
* <applet code="CheckboxDemo.class" width=200 height=75>
* </applet>
*/
How to Execute this Example??
d:\> javac CheckboxDemo.java
d:\> appletviewer CheckboxDemo.java
Output:
0 comments :
Post a Comment