Event Handling

A GUI library is no use if it can't handle events such as clicking a button, selecting a checkbox or dragging a slider thumb.

When a key is pressed or a mouse is moved the OS (Operating System) generates an event which is then passed to the currently active application. If our running sketch is currently the ative application it will receive these events and and pass them to a special method (function) that will process the event, this is called the event handler.

G4P provides two event handling mechanisms

  1. by control type : a single event handler for all controls of a particular type e.g. buttons
  2. by control : a single event handler for each control

In general you would use one or the other but it is possible to use both mechanisms in the same sketch.

If you are creating simple GUIs then I suggest you consider using GUI Builder, a graphical GUI editor created specifically for G4P and Processing. GUI Builder uses the second mechanism.