Interfascia

Class Listing

IFTextField
IFRadioController
IFRadioButton
IFProgressBar
IFLookAndFeel
IFLabel
IFCheckBox
IFButton
GUIEvent
actionPerformed
GUIController

Examples

Text Field
Temperature Converter
Radio Buttons
Custom Widget Color
Button

IFButton

The IFButton object creates a new button GUI component.

Syntax

IFButton b = new IFButton("Click Me", 30, 30);
b.addActionListener(this);

Method Summary

IFButton(String label, int x, int y);
IFButton(String label, int x, int y, int width);;

  • label, the text displayed on the button.
  • x, the X position of the button's upper left hand corner..
  • y, the Y position of the button's upper left hand corner.
  • width, the width in pixels of the button.

setLabel(String newLabel)

  • Sets the name of the button. The button name is used when submitting the interface's current state to a web server.
  • newLabel, the new name for the button.

getLabel()

  • Returns the button's name as a String.

setWidth(int width)

  • Sets the width of the button.
  • width, the new width for the button.

getWidth()

  • Returns the width in pixels of the button in integer form.

setHeight(int height)

  • Sets the height of the button.
  • height, the new height for the button.

getHeight()

  • Returns the height in pixels of the button in integer form.

setSize(int width, int height)

  • A convenience method to set both dimensions of the button.
  • width, the new width for the button.
  • height, the new height for the button.

setX(int x)

  • Sets the X position of the button relative to its GUIController.
  • x, the new X position for the button.

getX()

  • Returns the X position in pixels of the button relative to its GUIController.

setY(int y)

  • Sets the Y position of the button relative to its GUIController.
  • y, the new Y position for the button.

getY()

  • Returns the Y position in pixels of the button relative to its GUIController.

setPosition(int x, int y)

  • A convenience method to set both the X and Y position of the button.
  • X, the new X position for the button.
  • Y, the new Y position for the button.

addActionListener(Object listener)

  • Adds an action listener object which receives `GUIEvent` notifications when the button is clicked or released. You must implement the [actionPerformed()](/documentation/actionperformed/) method in order to receive events from the button.
  • listener, the object that events are sent to. (Usually `this`.)

Example

import interfascia.*;

GUIController c;
IFButton b1, b2;

void setup() {
  c = new GUIController (this);
  
  b1 = new IFButton ("One", 30, 20, 40, 17);
  b2 = new IFButton ("Two", 30, 60, 40, 17);

  b1.addActionListener(this);
  b2.addActionListener(this);

  c.add (b1);
  c.add (b2);
}

void draw() {
}

void actionPerformed (GUIEvent e) {
  if (e.getSource() == b1) {
    println("Button one was clicked");
  } else if (e.getSource() == b2) {
    println("Button two was clicked");
  }
}