All About Checkbox in AWT in Java

A checkbox is a graphical component provides an 'ON'(true) and 'OFF'(false) state. Clicking on the checkbox changes its state from ON to OFF or OFF to ON.When the checkbox is clicked,AWT send an action event to the checkbox.This event's target is the checkbox and its object is a boolean,giving the new state to the checkbox.An application should override the action method of the checkbox or one of it's containing window in order to cause some action to occur.
Optionally several checkboxes can be grouped together into a check box group.At most one button in a group can be in the 'ON' state at any given point of time.Pushing a checkbox to turn it 'ON' forces any other checkbox in the group(that is 'ON') to 'OFF' state.

The class structure of the Checkbox is given as:

public class Checkbox extends java.awt.Component{
public Checkbox();//default constructor with no label.The checkbox is set to off (by default) and 
//is not part of any checkbox group
public Checkbox(String value);//creates a check box with label as the value given in the parameter
public Checkbox(String value,fencingType,boolean initialState);
public CheckBox(String label,ChechboxGroup group,boolean state);
//creates a checkbox with the specified label in the specified checkboxGroup and set to the specified state.
public void addNotify();
public String getLabel();
public boolean getState();
protected String paramString();
public CheckBoxGroup getCheckboxgroup();
public void setCheckboxGroup(CheckboxGroup g);
public void setLabel(String label);
public void setState(boolean state);
An Example:

Checkbox c3=new Checkbox("value",null,true);
All About Checkbox in AWT in Java All About Checkbox in AWT in Java Reviewed by Animesh Chatterjee on October 22, 2018 Rating: 5

No comments:

Powered by Blogger.