Button Demo and Documentation

Display sketch code: ButtonDemo.pde. The code for Button is in Clickable.pde

There are 3 constructors. The first and second differ only because the second provides selected colors. The third constructor creates a multistate button with as many states as colors provided in the color arrays.

Fields x, y, w, and h are for location of the top left corner, width, and height of the button.

class Button
extends Clickable

The basic common simple Clickable item.

** Button(int leftX, int topY, int theWidth, int theHeight, String theLabel,
                    color stdColor, color overColor)
- Constructor for Buttons that do not have a selected state.
** Button(int leftX, int topY, int theWidth,
                    int theHeight, String theLabel,
                    color stdColor, color overColor,
                    color selected, color overSelected)
- Constructor for Buttons with a selected state.
** Button(int leftX, int topY, int theWidth,
                    int theHeight, String theLabel,
                    int numColors, color[] stdColor, color[] overColor)
- Constructor for multistate Buttons. The color arrays are set up so that colorState = 0 is typically is the normal color, colorState = 1 would normally be the selected color. The number of colors in these arrays determines the number of states and both color arrays must have the same number of elements. Note: actually the parameter "numColors" is not used. It was added as a work-around for a bug in Processing.js.
* void display() - If visible, displays a rectangular button at the specified location. Uses the specified colors unless it is disabled.
** int toggle() - Toggles the colorState between 0 and the highest state possible(normally colorState 1). Sets selected to true if the new state is not 0.
** int nextState() - Used by multistate buttons to rotate to the next state. Could also be used by two state buttons.
* boolean isOver() - Determines if the cursor mouse is over the specified rectangle. If it is. then "over" is set true and it returns true. Always returns false if stillSearching_ is false.

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