Home arrow Java & J2EE arrow Page 5 - Java's Basic User Interface Components

The Checkbox Class - Java

To simplify user interaction and make data entry easier, you can use java controls. Controls are components, such as buttons, labels and text boxes, that can be added to containers like frames, panels and applets. The Java.awt package provides an integrated set of classes to manage user interface components.

  1. Java's Basic User Interface Components
  2. Adding a Control to a Container
  3. The Button Class
  4. The Label Class
  5. The Checkbox Class
  6. The CheckboxGroup Class
  7. The Choice List Class
  8. The TextField and TextArea Class
  9. Setting a Password Character
  10. TextArea
By: Gayathri Gokul
Rating: starstarstarstarstar / 22
October 20, 2003

print this article


Check Boxes are labeled or unlabeled boxes that can be either “Checked off” or “Empty”. Typically, they are used to select or deselect an option in a program, such as the “Disable sound” check boxes from a Windows screen.

Check Boxes are generally nonexclusive, which means that if you have six check boxes in container, all the six can either be checked or unchecked at the same time. This component can be organized into check box group, which is sometimes called radio buttons. Both kinds of check boxes are created using the Checkbox class. To create a nonexclusive check box you can use one of the following constructors:

  • Checkbox() creates an unlabeled checkbox that is not checked.
  • Checkbox(String) creates an unchecked checkbox with the given label as its string.

    After you create a checkbox object, you can use the setState(boolean) method with a true value as argument for checked checkboxes, and false to uncheck it. Six checkboxes are created in Example 4, which is an applet to enable you to select up to six courses at a time. All five checkboxes are unchecked only the second option is checked.

    Example 4

    <Applet code= “CheckboxTest.class”
    Width = 200
    Height = 150>

    Import java.awt.*;

    Public class CheckboxTest extends java.applet.Applet
    Checkbox c1 = new Checkbox (“Java”);
    Checkbox c2 = new Checkbox (“XML”);
    Checkbox c3 = new Checkbox (“VB”);
    Checkbox c4 = new Checkbox (“Oracle”);
    Checkbox c5 = new Checkbox (“SQL”);
    Checkbox c6 = new Checkbox (“ASP”);

    Public void init(){

    >>> More Java & J2EE Articles          >>> More By Gayathri Gokul

    blog comments powered by Disqus
  • escort Bursa Bursa escort Antalya eskort


    - More Java Bugs Lead to More Attacks
    - Oracle's Java One Brings News, Surprises
    - Oracle Patches Java Runtime Environment
    - Apple Syncs Java Update with Oracle
    - Spring 3.1 Java Development Framework Compat...
    - Jelastic Java PaaS Availability and Pricing ...
    - NetBeans 7.1 Released, Supports JavaFX 2
    - SolarWinds Releases Newest Version of Java M...
    - Free Monitoring Tool for Java Apps on Heroku
    - Heroku Adds JCloud Platform Support, Java 7 ...
    - Java SE 8 Speculation in Full Swing
    - Java SE 7 Now Available
    - New JVM Language and Java Reporting Tool
    - Java 7 Release Update and New Eclipse Toolkit
    - The Best Java Netbeans IDE Plugins

    Developer Shed Affiliates


    Dev Shed Tutorial Topics: