|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectcontrolP5.Controller
controlP5.Button
public class Button
A button triggers an event after it has been release. Events can be linked to
functions and fields inside your program/sketch. for a full documentation of
this controller see the Controller
class.
/** * ControlP5 button. * this example shows how to create buttons with controlP5. * * by andreas schlegel, 2009 */ import controlP5.*; ControlP5 controlP5; // this is only a note. // we will not use variable b in the code below. // we have to use controlP5.Button here since there // would be a conflict if we only use Button to declare button b. Button b; // a button-controller with name buttonValue will change the // value of this variable when pressed. int buttonValue = 0; int myColor = color(0,255,180); void setup() { size(640,480); smooth(); frameRate(30); controlP5 = new ControlP5(this); controlP5.addButton("buttonA",0,100,100,80,19); controlP5.addButton("buttonB",255,100,120,80,19); controlP5.addButton("buttonValue",128,100,140,80,19); } void draw() { background(myColor); fill(buttonValue); rect(20,20,width-40,height-40); } public void controlEvent(ControlEvent theEvent) { println(theEvent.controller().name()); } // function buttonA will receive changes from // controller with name buttonA public void buttonA(int theValue) { println("a button event from buttonA: "+theValue); myColor = theValue; } // function buttonB will receive changes from // controller with name buttonB public void buttonB(int theValue) { println("a button event from buttonB: "+theValue); myColor = theValue; }
Field Summary |
---|
Fields inherited from interface controlP5.ControlP5Constants |
---|
acceptClassList, ACTIVE, ALT, ARC, ARRAY, BACKSPACE, BOOLEAN, BOTTOM, CENTER, CONTROL, controlEventClass, CUSTOM, DECREASE, DEFAULT, DELETE, DOWN, ELLIPSE, ENTER, ESCAPE, EVENT, eventMethod, FIELD, FLOAT, HALF_PI, HIDE, HIGHLIGHT, HORIZONTAL, IMAGE, INCREASE, INTEGER, INVALID, KEYCONTROL, LEFT, LINE, LOAD, MENU, METHOD, MOVE, OVER, PI, PRESSED, PRINT, RELEASE, RESET, RIGHT, SAVE, SHIFT, SPRITE, STRING, SWITCH, SWITCH_BACK, SWITCH_FORE, TAB, TOP, TWO_PI, UP, VERBOSE, VERTICAL |
Constructor Summary | |
---|---|
Button()
|
|
Button(ControlP5 theControlP5,
java.lang.String theName)
|
Method Summary | |
---|---|
Button |
activateBy(int theValue)
A button can be activated by a mouse PRESSED or mouse RELEASE. |
void |
addToXMLElement(ControlP5XMLElement theElement)
|
boolean |
booleanValue()
Returns true or false and indicates the switch state of the button. |
void |
mousePressed()
|
void |
mouseReleased()
|
void |
mouseReleasedOutside()
|
Button |
setOff()
If the button acts as a switch, setOff will turn off the switch. |
Button |
setOn()
If the button acts as a switch, setOn will turn on the switch. |
Button |
setSwitch(boolean theFlag)
turn a button into a switch, or use toggle instead. |
void |
setValue(float theValue)
set the value of the button controller. |
java.lang.String |
toString()
|
void |
update()
updates the value of the controller without having to set the value explicitly. |
void |
updateDisplayMode(int theMode)
} |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Button()
public Button(ControlP5 theControlP5, java.lang.String theName)
Method Detail |
---|
public void mousePressed()
public void mouseReleased()
public Button activateBy(int theValue)
theValue
- use ControlP5.PRESSED or ControlP5.RELEASE as parameter
public void mouseReleasedOutside()
public void setValue(float theValue)
setValue
in class Controller
theValue
- floatpublic void update()
update
in interface ControllerInterface
update
in class Controller
public void addToXMLElement(ControlP5XMLElement theElement)
theElement
- ControlP5XMLElementpublic Button setSwitch(boolean theFlag)
theFlag
- turns the button into a switch when true
Toggle
public Button setOn()
setSwitch
to turn a button into a switch.
public Button setOff()
setSwitch
to turn a button into a switch.
public boolean booleanValue()
setSwitch
should have been set before.
setSwitch(boolean)
public void updateDisplayMode(int theMode)
Controller.updateDisplayMode(int)
public java.lang.String toString()
toString
in class Controller
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |