Create AWT Checkbox Example
- /*
- Create AWT Checkbox Example
- This java example shows how to create a Checkbox using AWT Checkbox class.
- */
- import java.applet.Applet;
- import java.awt.Checkbox;
- /*
- <applet code="CreateCheckBox" width=200 height=200>
- </applet>
- */
- public class CreateCheckBox extends Applet{
- public void init(){
- /*
- * To create a checkbox use
- * Checkbox() constructor.
- */
- Checkbox checkBox1 = new Checkbox();
- /*
- * Set Checkbox caption or label using
- * void setLabel(String text)
- * method of AWT Checkbox class.
- */
- checkBox1.setLabel("My Checkbox 1");
- /*
- * To create checkbox with the caption use
- * CheckBox(String text) constructor of
- * AWT Checkbox class.
- */
- Checkbox checkbox2 = new Checkbox("My Checkbox 2");
- //add checkboxes using add method
- add(checkBox1);
- add(checkbox2);
- }
- }
Example Output




