Notice: This is a static archive of the Mobile Processing website, as the project is no longer significantly active. All forms and the Discourse boards are no longer functional, and the mobile website at http://wapmp.at/ is no longer available. Please visit the Mobile Processing Google Group for any remaining discussions and the Processing website for the latest news about Processing.
Index
Name

PButton

Examples
PButton button;
PFont font;
boolean toggle;

void setup() {
  //// create the button with the label "Toggle"
  button = new PButton("Toggle");
  //// let the button size itself based on the label
  button.calculateBounds(0, 0, width, height);
  //// now move it to the middle of the screen,
  //// without changing its dimensions
  button.setBounds((width - button.width) / 2, 
                   (height - button.height) / 2, 
                   button.width, 
                   button.height);
  //// let the button do any final initialization
  button.initialize();
  
  //// set up the font for drawing to the screen
  font = loadFont();
  textFont(font);
  textAlign(CENTER);
}

void draw() {
  background(200);
  
  //// draw the button
  button.draw();
  if (toggle) {
    //// draw the toggle text underneath the button
    text("On!", width / 2, 
         button.y + button.height + 4 + font.baseline);
  }
}

void keyPressed() {
  //// let the button handle any keypresses
  button.keyPressed();
}

void keyReleased() {
  //// let the button handle any keyreleases. this is
  //// important as PButton sends its event on release!
  button.keyReleased();
}

void libraryEvent(Object library, int event, Object data) {
  if (library == button) {
    //// if the button sent a library event, it was pressed!
    toggle = !toggle;
  }
}

Description A button component. A button can calculate its bounds based on the size of its text label.
Fields
font   The font used to display the button label text.

fontColor   Color of the button label text.

label   The button label text.

Methods
keyPressed()   Handles pressing the button when the FIRE button is pressed.

keyReleased()   Releases the pressed state of this button when the FIRE button is released.

Constructors
PButton(label)
Parameters
label   button label text