# Controller

description
  Controller is an abstract class that is extended by all available controllers. this is the full documentation list for all methods available for a controller.

+Example

      /**
       * controlP5numberbox by andreas schlegel <br />
       * an example to show how to use a numberbox to control<br />
       * variables and events.<br />
       * click a numberbox and move mouse up and down while pressing <br />
       * the mousebutton to change values.<br />
       * for further information and questions about controlP5 first<br />
       * take a look at the documentation, the examples, or the <br />
       * website at http://www.sojamo.de/controlP5<br />
       */

      import controlP5.*;

      ControlP5 controlP5;

      public int myColorRect = 200;

      public int myColorBackground = 100;

      void setup() {
        size(400,400);
        frameRate(25);
        controlP5 = new ControlP5(this);
        controlP5.addNumberbox("numberbox1",myColorRect,100,160,100,14).setId(1);
        controlP5.addNumberbox("numberbox2",myColorBackground,100,200,100,14).setId(2);
        controlP5.addSlider("slider1",100,200,100,100,250,100,14).setId(3);
        controlP5.addTextfield("text1",100,290,100,20).setId(4);
      }

      void draw() {
        background(myColorBackground);
        fill(myColorRect);
        rect(0,0,width,100);
      }

      void controlEvent(ControlEvent theEvent) {
        println("got a control event from controller with id "+theEvent.controller().id());
        switch(theEvent.controller().id()) {
          case(1):
          myColorRect = (int)(theEvent.controller().value());
          break;
          case(2):
          myColorBackground = (int)(theEvent.controller().value());
          break;
        }
      }

Methods

addListener ( )
  add a listener to the controller.

behavior ( )
  get the behavior of the controller.

defaultValue ( )
  returns the default value.

getTab ( )
  get the tab the controller belongs to.

getWindow ( )
  get the control window of the controller

hide ( )
  hide the controller, make it invisible.

id ( )
  get the id of the controller.

isUpdate ( )
  enable the update function for a controller.

isVisible ( )
  check if the controller is visible.

label ( )
  get the label of the controller.

moveTo ( )
  move a controller to another tab and/or controlWindow.

name ( )
  returns the name of the controller.

position ( )
  get the position of a controller. e.g. Controller.position().x();

remove ( )
  remove a controller from controlP5.

removeBehavior ( )
  remove the behavior from the controller.

removeListener ( )
  remove a listener from the controller.

setBehavior ( )
  with setBehavior you can apply behaviors to a controller

setColorActive ( )
  set the color for the controller while active.

setColorBackground ( )
  set the background color of the controller.

setColorForeground ( )
  set the foreground color of the controller.

setColorLabel ( )
  set the color of the text label of the controller.

setColorValue ( )
  set the color of the value label of the controller.

setDefaultValue ( )
  set the default value.

setGroup ( )
  set the group of the controller.

setId ( )
  set the id of the controller.

setLabel ( )
  set the label of the controller.

setLabelVisible ( )
  show or hide the labels of a controller.

setMoveable ( )
  enable or prevent the controller to be moveable.

setPosition ( )
  set the position of a controller.

setTab ( )
  set the tab of the controller.

setUpdate ( )
  disable the update function for a controller.

setValue ( )
  set the value of the controller.

setVisible ( )
  set the visibility of a controller.

show ( )
  show the controller. make it visible.

stringValue ( )
  set the current string value of a controller.

trigger ( )
  trigger the event of a controller. deprecated. use .update() instead.

update ( )
  updates the value of the controller without having to set the value explicitly. update does not visually update the controller. the updating status can be set with setUpdate(true/false) and checked with isUpdate().

value ( )
  get the current value of the controller.

usage
  Web & Application

related
  - Bang
  - Button
  - Knob
  - Matrix
  - MultiList
  - Numberbox
  - Radio
  - ScrollList
  - Slider
  - Textarea
  - Textfield
  - Textlabel
  - Toggle
  - ControlGroup
  - ControlBehavior
  - ControlEvent