G4P (GUI for Processing) 4.3.9
A set of GUI controls for your Processing sketch.
Loading...
Searching...
No Matches
g4p_controls.GTimer Class Reference
Inheritance diagram for g4p_controls.GTimer:

Public Member Functions

int getInitialDelay ()
 
int getInterval ()
 
int getNbrRepeats ()
 
 GTimer (PApplet theApplet, Object obj, String methodName, int delay)
 
 GTimer (PApplet theApplet, Object obj, String methodName, int delay, int initDelay)
 
boolean isRunning ()
 
boolean isValid ()
 
void setDelay (int delay)
 
void setInitialDelay (int initDelay)
 
void setInterval (int interval)
 
void setNbrRepeats (int nbrRepeats)
 
void start ()
 
void start (int nrepeats)
 
void stop ()
 

Protected Member Functions

void createEventHandler (Object handlerObj, String methodName)
 
void fireEvent ()
 

Protected Attributes

final PApplet app
 
Method eventHandlerMethod = null
 
String eventHandlerMethodName
 
Object eventHandlerObject = null
 
int nbrRepeats = -1
 
Timer timer = null
 

Detailed Description

This class is used to trigger events at user defined intervals. The event will call a user defined method/function. The only restriction is that the method used has a single parameter of type GTimer and returns void eg

void fireBall(GTimer timer){ ... }


Each timer object must have its own handler

It has no visible GUI representation so will not appear in the GUI.

Author
Peter Lager

Constructor & Destructor Documentation

◆ GTimer() [1/2]

g4p_controls.GTimer.GTimer ( PApplet  theApplet,
Object  obj,
String  methodName,
int  delay 
)

Create the GTimer object with this ctor.

'methodName' is the method/function to be called every 'interval' milliseconds. 'obj' is the object that contains the method/function 'methodName'

For most users 'methodName' will be in their main sketch so this parameter has the same value as 'theApplet'

Parameters
theAppleta reference to the PApplet object (invariably this)
objthe object that has the method to be executed (likely to be this)
methodNamethe name of the method to be called by the timer
delaythe initial delay and the time (in millisecs) between function calls

◆ GTimer() [2/2]

g4p_controls.GTimer.GTimer ( PApplet  theApplet,
Object  obj,
String  methodName,
int  delay,
int  initDelay 
)

Create the GTimer object with this ctor.

'methodName' is the method/function to be called every 'interval' milliseconds. 'obj' is the object that contains the method/function 'methodName'

For most users 'methodName' will be in their main sketch so this parameter has the same value as 'theApplet'

Parameters
theAppleta reference to the PApplet object (invariably this)
objthe object that has the method to be executed (likely to be this)
methodNamethe name of the method to be called by the timer
delaythe time (in millisecs) between function calls
initDelaythe initial delay (in millisecs) before calling method

Member Function Documentation

◆ createEventHandler()

void g4p_controls.GTimer.createEventHandler ( Object  handlerObj,
String  methodName 
)
protected

See if 'obj' has a method called 'methodName' that has a single parameter of type GTimer and if so keep a reference to it.

Parameters
obj
methodName

◆ fireEvent()

void g4p_controls.GTimer.fireEvent ( )
protected

Attempt to fire an event for this timer. This will call the method/function defined in the ctor.

◆ getInitialDelay()

int g4p_controls.GTimer.getInitialDelay ( )

Get the initial delay time (milliseconds).

Returns
initial delay in millsecs or -1 if the timer failed to be created.

◆ getInterval()

int g4p_controls.GTimer.getInterval ( )

Get the interval time (milliseconds) between events.

Returns
interval in millsecs or -1 if the timer failed to be created.

◆ getNbrRepeats()

int g4p_controls.GTimer.getNbrRepeats ( )

The number of times an event is to be fired.

Returns
the nbrRepeats

◆ isRunning()

boolean g4p_controls.GTimer.isRunning ( )

Is the timer running?

Returns
true if running

◆ isValid()

boolean g4p_controls.GTimer.isValid ( )

See if the GTimer object has been created successfully

Returns
true if successful

◆ setDelay()

void g4p_controls.GTimer.setDelay ( int  delay)

Sets the initial delay and the interval between events.
This is equivalent to calling both -

setInterval(delay);
setInitialDelay(delay);


Parameters
delayinitial delay and interval in milliseconds

◆ setInitialDelay()

void g4p_controls.GTimer.setInitialDelay ( int  initDelay)

Set the delay before the first event is triggered

Parameters
initDelayinitial delay in milliseconds

◆ setInterval()

void g4p_controls.GTimer.setInterval ( int  interval)

Set the interval between events

Parameters
intervaldelay between events in milliseconds

◆ setNbrRepeats()

void g4p_controls.GTimer.setNbrRepeats ( int  nbrRepeats)

The number of times an event is to be fired.

Parameters
nbrRepeats≥ 0 keep running until stopped by user

◆ start() [1/2]

void g4p_controls.GTimer.start ( )

Start the timer (call the method forever)

◆ start() [2/2]

void g4p_controls.GTimer.start ( int  nrepeats)

Start the timer and call the method for the number of times indicated by nrepeats. If nrepeats is ≤0 then repeat forever

Parameters
nrepeatsthe number of times to repeat the action

◆ stop()

void g4p_controls.GTimer.stop ( )

Stop the timer (can be restarted with start() method)