Home | » | Java | » | Advance Java | » | Java AWT (Abstract Window ToolKit) | » | CheckBoxes |
---|
The Checkbox are used where there are multiple options for a user and a user have a option to Select any Options either he may choose only a Single Option or either he may select all options. The check boxes have two states selected or un-selected or true and false or on and off, etc. There are two Types of Checkboxes in Java.
1. Non exclusive- in this we can select a series of check boxes.
2. Exclusive – in this we can select only one form a given Series of Options of from Checkboxes. It behaves like a Radio or option Button.
For creating check Box.
- Checkbox() create empty.
- Checkbox(String) with a string
- Checkbox(String,Boolean) This will first creates a check box with text string and then it specifies whether it is selected or unselected.
- Checkbox(String, Boolean, null ) the null is used for specifying whether it is part of a checkbox group or no CheckboxGroup used to Create Option Buttons from the Checkboxes and Third Argument of Checkbox will determine whether a Checkbox is a Part of Option Buttons because JAVA doesn't provide a Separate Method For Creating an Option or Radio Buttons. For Creating a Option Button we have to use CheckboxGroup and then Specify the name of CheckboxGroup while Creating a Checkbox as like this.
CheckBox c=new CheckBox("City", True, cg);
The following example displays checkboxes on the applet using the Checkbox class.
The above code will be stored in the file called ButtonTest.java, which on compilation will crate a class file called Button.class. Now compiple this file using below commands in the DOS mode:
C:\>jdk1.4\bin>javac CheckBoxTest.java
C:\>jdk1.4\bin>appletviewer CheckBoxTest.java
|
||
Download Complete Program |
Methods of the Button Object:
getLabel() | used for Retrieving the text of Checkbox. |
setLabel(String) | Used to Specify the Text of Checkbox. |
getState() | Check whether a Checkbox is Selected or Not. |
setState(Boolean) | Used to set the State either True or false. |
AWT Controls
Label | Buttons | Check Boxes | Radio Buttons | |
Choice Controls | TextFields & Password | TextAreas | Scrolling Lists | Scrollbars |
No comments:
Post a Comment