ButtonGroup Demo and Documentation

ButtonGroups can hold any type of button. They are used in ListBoxes, ComboBoxes, and menus but can be used by themselves. The demo uses two regular buttons, a circle button (used as a radio button) and a checkbox.

Buttons groups do not have a particular display and hence do not use the fields x, y, w, and h.

Display sketch code: ButtonGroupDemo.pde. The code for ButtonGroup is in: Clickable.pde.

class ButtonGroup
extends Clickable

Used primary as basis for a ListBox and indirectly by ComboBox and Menu. However, it could be used by itself when a grouping of buttons is desired but a ListBox is not appropriate.

Additional fields

Button[] buttonArray - The array of buttons in the group.
String selectedLabel - The label of the selected button.
** ButtonGroup(Button[] aButtonArray)
- Creates a Button Group given an array of buttons. One of the buttons will be selected. If this is undesirable, make sure that the buttons have only one colorState.
** void setEnabled(boolean b)
- Sets the group and all its members to enabled or disabled.
** void setVisible (boolean b)
- Sets the group and all its members to visible or hidden.
* void display()
- Displays all the visible buttons in the group assuming the group is visible.
* boolean isOver()
- Does a isOver() for each of the buttons in the group. Sets the "over" field for the group and then returns over. Is called by checkForClick() in the mouseReleased() method and must be called by the user's draw() method to update the "over" field before it is drawn.
* boolean checkForClick()
- Assuming that the group is visible and enabled, it checks all group members to see if they have been clicked. It must be used (directly or indirectly) in the mouseReleased method. If a button has been clicked, it sets setSelectedItemNum and clickedItemNum in addition setting the "clicked" field to true. It returns true if a button was clicked.
* boolean hasBeenClicked()
- Used to indicate the a click to a button in the group has been processed and the "clicked" field has been set to false. Called by draw() or a submethod of draw(). It clears the "clicked" field in the clicked button.
* int getClickedItemNum()
- Returns clickedItemNum.
** void setSelectedItemNum(int b)
- Sets all the buttons to unselected and then sets the specified button to selected. Good for a radio button group.
** Button getSelectedItem()
- Returns the selected button.
** String getSelectedLabel()
- Returns label of selected button.
** Button getItem(int i)
- After error checking, it returns the specified button.
** int getGroupLength()
- Returns the number of buttons in the group.

Method use codes:

** This constructor or method is designed to be called in the user sketch.

* This method is normally not called in the user's sketch unless the Clickable item was not been included in a ClickableGroup. ClickableGroup automatically uses the method as needed. Exception: This method may be needed if the user is extending Clickable with a new class.

# This constructor or method is rarely used in the user program. In Java, it would probably marked "private". Clickable, ScrollBar, and some other abstract constructors would never be called directly by the user sketch because they do nothing useful unless the user is extending a class.


Inherited from Clickable

Fields
NOTHING_CLICKED, COMBO_BUTTON, DISABLED_COLOR, borderColor, c, clicked, clickedItemNum, colorState, enabled, h, label, over, overC, scrollable, selected, selectedItemNum, visible, w, x, y

Constructors
Clickable

Methods
checkForClick, display, doNotSelect, getClickedItemNum, getColorState, getH, getItem, getLabel, getSelected, getSelectedItem, getSelectedItemLabel, getSelectedItemNum, getW, getX, getY, hasBeenClicked, hideSomething, isOver, setBorderColor, setColorState, setH, setLabel, setScrollable, setSelected, setSelectedItemNum, setEnabled, setVisible, setW, setX, setY, sX, sY

Return to the top of the page

Revised: 04/11/2014