G4P (GUI for processing)

This library provides a rich collection of 2D GUI controls for your sketch. It also supports multiple windows and a simple but customizable event handling system.

Controls Features

Label
Button
Image button
Image toggle button
Checkbox
Option
Droplist
Slider
Slider2D
Custom slider
Stick
Knob
Password field
TextField (with scrollbar)
TextArea (with scrollbars)
SketchPad (embedded graphics)
Panel (moveable and collapsable)
Timer
Multiple windows

There are eight predefined colour schemes to give a consistent look and feel to the controls. V3 has better text clarity in all 2D/3D rendering modes. Styles (attributes) can now be applied to text e.g. bold, italic, sub/super script etc.

TextField and TextArea controls support copy and paste using the clipboard as well as tab to control which is useful for form filling.

Simple and consistent event handling model allows for handling events by control type. Users can also create event handlers for a specific control(s)

G4P now uses double buffering for all visible controls and although it reduces the workload on the processor it requires more memory.

When creating a control it is now necessary to specify a rectangular area of the display for the control, and the control must fit inside this area. So all visible controls (apart from GWindow) requires a minimum of 5 parameters. So to create a GButton object the statement might be

GButton button = new GButton(this, p0, p1, p2, p3);

where the parameters are

  • the applet responsible for drawing this component (unless you have multiple windows the value will be this)
  • the x/y coordinates of the top-left corner
  • the width and height of the control area
  • Note: THis is the default order and is the same as the CORNER constant used by Processing for drawing rectangles and ellipses. It is also possible to change the meaning of the parameters by setting the create mode to CORNERS or CENTER.

G4P will then create a control to fit the area (in some cases such as GSlider yiou might miss some of the detail - if that happens increase the width and/or height)

Depending on the type of control some constructors accept more parameters if it makes sense e.g.

            GButton button = new GButton(this, p0, p1, p2, p3, "Click Me!";
             
             

To find out about specific constructors look at the reference material for that control class.

Click on the examples link to look and experimant with the controls available. All the examples are included in the library download.

If you want to be able to create separate windows then look at the Simple windows example, this page discusses how to write sketches using this feature.