home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-01-24 | 1.4 KB | 68 lines |
- package COM.odi.demo.OSDraw;
-
- /**
- * <H3>Copyright (C) Object Design Inc. 1996, 1997</H3>
- */
-
- import java.util.Vector;
- import java.awt.*;
-
- /*
- * Class CheckboxMenuGroup handles CheckboxMenuItem instances
- */
-
- public class CheckboxMenuGroup {
-
- // Vector to keep track of CheckboxMenuItem instances
- private Vector items;
-
- // Constructor
-
- public CheckboxMenuGroup() {
- items = new Vector();
- }
-
- // Add a CheckboxMenuItem instance
-
- public void add(CheckboxMenuItem item) {
- items.addElement(item);
- }
-
- // Select an item at its index
-
- public void select(int index) {
- if (index < 0 || index >= items.size()) {
- return;
- }
- for (int i = 0; i < items.size(); i++) {
- CheckboxMenuItem check = (CheckboxMenuItem)(items.elementAt(i));
- if (i == index) {
- check.setState(true);
- }
- else {
- check.setState(false);
- }
- }
- }
-
- // Try to select a particular item
- // If the CheckboxMenuGroup constains the item, return its index
- // Default return -1
-
- public int select(CheckboxMenuItem item) {
- if (item == null) {
- return -1;
- }
- int index = items.indexOf(item);
- if (index < 0) {
- return index;
- }
- for (int i = 0; i < items.size(); i++) {
- CheckboxMenuItem check = (CheckboxMenuItem)(items.elementAt(i));
- check.setState(false);
- }
- item.setState(true);
- return index;
- }
- }
-