Since all classes you put in a Processing's sketch are actually inner classes
of the top class (which is the sketch itself);
all field variables (that is non-local variables), are accessible throughout the whole sketch!
The only catch is that 1st you need to instantiate a class before using its field variables.
However, if it's a primitive constant or a
String, you may decide to turn it
static.
This way, it can be used directly, w/o instantiating it 1st:
class Example {
// final constants:
static final int DIMENSION = 0100;
static final color COLOUR = #FFFF00;
// regular fields:
int x, y;
Example(int xx, int yy) {
x = xx;
y = yy;
}
}
void setup() {
size (200, 100);
noLoop();
fill(Example.COLOUR); // direct constant field access
// Class instantiation:
final Example e = new Example(width >> 1, height >> 1);
// Using both regular object fields & static fields:
ellipse(e.x, e.y, Example.DIMENSION, Example.DIMENSION);
}
Interfaces are also good for it. All their fields are
static
final by definition.
Take a look at program "Hero Maze" in this post below, which uses interfaces that way a lot: