Class jclass.contrib.JCCheckboxGroup
All Packages Class Hierarchy This Package Previous Next Index
Class jclass.contrib.JCCheckboxGroup
java.lang.Object
|
+----java.awt.CheckboxGroup
|
+----jclass.contrib.JCCheckboxGroup
- public class JCCheckboxGroup
- 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. JCCheckboxGroup stores the checkboxes
in a Vector.
While JCCheckboxGrop manages AWT Checkbox instances,
it works best with JCCheckbox instances. The JCCheckbox constructor will
automatically call the addCheckbox() member.
Here is a typical use of the JCCheckboxGroup class:
public myForm extends Panel {
int colorValues = { BLUE, GREEN, VIOLET };
String colorStrings = {"Blue", "Green", "Violet"};
JCCheckbox colorG;
public myForm() {
setLayout(new JCRowColLayout(-1, 1));
colorG = JCCheckbox.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.
-
JCCheckboxGroup()
-
-
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 JCCheckbox.
-
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".
JCCheckboxGroup
public JCCheckboxGroup()
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 JCCheckbox getCurrentJC()
- Retrieves the currently-selected JCCheckbox. This function
only works if the current selection is a JCCheckbox.
- Returns:
- the currently-selected JCCheckbox (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 JCCheckbox and JCCheckboxGroup
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 };
JCCheckboxGroup boxG;
public getColor() {
boxG.set(boxValues, myObject.getColor());
}
All Packages Class Hierarchy This Package Previous Next Index