Checkbox Demo and Documentation

Display sketch code: CheckboxDemo.pde. The code for Checkbox is in Clickable.pde

Check boxes automatically toggle when clicked. There are two constructors. The first does not provide a background button and the user must click the little box. The second provides a background button and the user can click anywhere in the button.

class Checkbox
extends Button
which extends Clickable

There are two distinct kinds of Checkbox. Both have a small box that changes from white to black when the button is selected. The first constructor creates a Checkbox without a background button so the user must click the small box. The second places the CheckBox inside are regular button. This is generally preferable when the Checkbox is part of ListBox, ComboBox or Menu.

Additional fields

boolean showPanel - (I.E. showButton) True if there is a button background (second constructor), false if not (first constructor).
** Checkbox(int leftX, int topY, String theLabel)
- Create a special two state button that looks and acts like a check box. There is a small box that blackens when checked. The label appears to the right of the box. The user must click the small box to toggle it. It should NOT be used as a radio button in a group because it toggles automatically. There is no background panel or button behind the CheckBox.
** Checkbox(int leftX, int topY, int theWidth, int theHeight, String theLabel,
                    color stdColor, color overColor)
- Creates a two state button that looks and acts like a check box. There is a small box that blackens when checked. The label appears to the right of the box. The Checkbox appears on top of a standard rectangular Button. The user can click anywhere in the enclosing button. It should NOT be used as a radio button in a group because it toggles automatically.
* boolean checkForClick()
- If the mouse cursor is over the square (first constructor) or over the button (second constructor), it toggles the check mark and sets clicked to true. It returns true if the button was clicked.
* void display()
- Display the Checkbox with or without a button. If showPanel is false, the CheckBox is square with label on the right. If it true, "super" draws a standard button and box is drawn on top of it.
** boolean doNotSelect()
- This method should be used when the Checkbox is part of a ListBox of some type and should not be selected to indicate that it was the last item selected. Instead selected refers to whether or not the Checkbox is white or black.

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 Button

Constructors
Button, Button, Button

Methods
display, isOver, nextState, toggle


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