    All Packages  Class Hierarchy  This Package  Previous  Next  Index

# Class jclass.contrib.ContribCheckboxGroup

    java.lang.Object
       |
       +----java.awt.CheckboxGroup
               |
               +----jclass.contrib.ContribCheckboxGroup

public class ContribCheckboxGroup
extends CheckboxGroup

The Java AWT CheckboxGroup class does not allow access to the checkboxes it manages. This makes the task of manipulating checkbox groups awkward. ContribCheckboxGroup stores the checkboxes in a Vector. While ContribCheckboxGrop manages AWT Checkbox instances, it works best with ContribCheckbox instances. The ContribCheckbox constructor will automatically call the addCheckbox() member. Here is a typical use of the ContribCheckboxGroup class:

    public myForm extends Panel {
    int colorValues      = { BLUE, GREEN, VIOLET };
    String colorStrings  = {"Blue", "Green", "Violet"};
    ContribCheckbox colorG;
    public myForm() {
    setLayout(new JCRowColLayout(-1, 1));
    colorG = ContribCheckbox.makeGroup(this, colorStrings, colorValues);
    }
    private int getColor();
    private void setColor(int);
    public void getData() {
    colorG.set(colorValues, getColor());
    }
    public void setData() {
    setColor(colorG.getCurrentJC().value);
    }
    }

If items change, simply change the colorValues and colorStrings arrays. This makes mapping from the checkbox to the attribute to set a relatively easy task.

##

ContribCheckboxGroup()

##

addCheckbox(Checkbox)
  Adds a specified checkbox to the list of managed checkbox.
getCheckbox(int)
  Retrieves the checkbox at the specified index.
getCurrentJC()
  Retrieves the currently-selected ContribCheckbox.
numCheckboxes()
  Returns the number of Checkbox instances that have been stored.
set(int[], int)
  Sets the currently-selected checkbox to that containing the value "val".

##

ContribCheckboxGroup

      public ContribCheckboxGroup()

##

addCheckbox

      public void addCheckbox(Checkbox item)

  Adds a specified checkbox to the list of managed checkbox. When addCheckbox() is called, it does not impose any layout restrictions; it adds the item to an array for retrieval by getCheckbox(). Checking for duplicate items is not done.

  Parameters:
    item - this is the Checkbox instance to add

numCheckboxes

      public int numCheckboxes()

  Returns the number of Checkbox instances that have been stored.

  Returns:
    the number of items in the array of checkboxes

getCheckbox

      public Checkbox getCheckbox(int i)

  Retrieves the checkbox at the specified index. An object is returned only if it is derived from the AWT checkbox class.

  Parameters:
    i - this is the index of the item
  Returns:
    the Checkbox instance, or null if not found

getCurrentJC

      public ContribCheckbox getCurrentJC()

  Retrieves the currently-selected ContribCheckbox. This function only works if the current selection is a ContribCheckbox.

  Returns:
    the currently-selected ContribCheckbox (an object representing the selected checkbox in the group)

set

      public void set(int values[],
                      int val)

  Sets the currently-selected checkbox to that containing the value "val". Typically, using ContribCheckbox and ContribCheckboxGroup involves creating an array representing values assigned to each checkbox. This function takes the array and the desired value, finds the checkbox item, and makes that checkbox the current item. This makes it relatively easy to set checkbox values based on user data. For example:

      int boxValues[] = { BLUE, GREEN, VIOLET };
      ContribCheckboxGroup boxG;
      public getColor() {
      boxG.set(boxValues, myObject.getColor());
      }

    All Packages  Class Hierarchy  This Package  Previous  Next  Index