A check box is a graphical component that can be in either an "on" (true) or "off" ........
Applying checkbox
A check box is a control that is used to turn an option on or off. It consists of a small box that can either contain a check mark or not. There is a label associated with each check box that describes what option the box represents. You change the state of a check box by clicking on it. Check boxes can be used individually or as part of a group. Check boxes are objects of the Checkbox class.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."Checkbox supports these constructors:
- Checkbox():
Creates a check box with an empty string for its label.
- Checkbox(String label):
Creates a check box with the specified label.
- Checkbox(String label, boolean state):
Creates a check box with the specified label and sets the specified state.
- Checkbox(String label, boolean state, CheckboxGroup group):
Constructs a Checkbox with the specified label, set to the specified state, and in the specified check box group.
- Checkbox(String label, CheckboxGroup group, boolean state):
Creates a check box with the specified label, in the specified check box group, and set to the specified state
.
methods
- getLabel(): Gets the label of this check box.
syntax:
boolean getState()
- setLabel(String label) : Sets this check box's label to be the string argument.
Syntax:
void setLabel(String str)
- getState(): Determines whether this check box is in the "on" or "off" state.
syntax:
boolean getState()
- setState(boolean on): Sets the state of this check box to the specified state.
syntax:
void setState(String str)
sample program for applying checkboxes
import java.awt.*;
import java.applet.Applet;
public class MyCheckbox extends Applet
{
public void init()
{
Checkbox c = new Checkbox("Choose this option");
add(c);
}
}
output of this sample program:
No comments :
Post a Comment