SpringGUI

introduction    download    reference    examples    faq


Reference

Name

handleEvent()

Examples

void handleEvent(String[] parameters) {
  // This will print a message whenever any of the buttons in
  // SpringGUI has been pushed.
  if ( parameters[0].equals("Button") &&
       parameters[2].equals("mouseClicked") ) {
    println("You have clicked any Button!");
  }
}

Description

handleEvent() is the method you must implement in your Processing sketches for SpringGUI to work. handleEvent() is called by SpringGUI whenever an event takes place on one of the GUI elements you have created. The method receives the parameters of the event as an Array of Strings which you can compare in order to get more information about the event.

The String[] Array's length varies with different types of events, but parameters 0 to 2 always refer to the type of GUI element, name of the element and the name of the event respectively.

Note that in Processing, you cannot compare Strings directly but must do so via the method String1.equals(String2). Also please be precise in the comparison of parameters (capitalisation is important, for example), as typos will cause the comparisons to return false.

If you are an advanced user who would like to gain access to the underlying classes that are used in SpringGUI, you can implement void handleEvent(Object[] parameters) instead of void handleEvent(String[] parameters). If you do so, SpringGUI will initialise in advanced mode. You will receive the same parameters as in beginner mode but the Array will contain two additional objects referencing the java.awt.Component the event took place on and the event object (java.awt.event.MouseEvent, for instance). You will also receive all parameters as Objects instead of Strings, so you will have to cast them to Strings manually.

Syntax

void handleEvent(String[] parameters) {
  // your event-handling code goes here
}

Parameters

String[] parameters This is the array of parameters your event-handling method will receive.

Returns

nothing

Related

table of events
absolute beginner in Processing?


back to the top of the page


tinkering with codetools and docsscrapbookabout