Game Control Plus  1.2.2
 All Classes Namespaces Functions Variables Pages
org.gamecontrolplus.gui.MTimer Class Reference
Inheritance diagram for org.gamecontrolplus.gui.MTimer:

Public Member Functions

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

Protected Member Functions

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

Protected Attributes

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

Additional Inherited Members

- Public Attributes inherited from org.gamecontrolplus.gui.MConstantsInternal
String SLIDER_STYLES = "|grey_blue|blue18px|green_red20px|purple18px|red_yellow18px|"
 
String DEFAULT_SLIDER_STYLE = "grey_blue"
 
int DRAW_METHOD = 0x00000001
 
int MOUSE_METHOD = 0x00000002
 
int PRE_METHOD = 0x00000004
 
int KEY_METHOD = 0x00000008
 
int POST_METHOD = 0x00000010
 
int ALL_METHOD = 0x0000001f
 
int RUNTIME_ERROR = 0xf0000000
 
int MISSING = 0x01000001
 
int NONEXISTANT = 0x01000002
 
int EXCP_IN_HANDLER = 0x81000003
 
int OFF_CONTROL = 0
 
int OVER_CONTROL = 1
 
int PRESS_CONTROL = 2
 
int DRAG_CONTROL = 3
 
int TINT_FOR_ALPHA = 255
 
int I_NONE = 0
 
int I_TL = 1
 
int I_TR = 2
 
int I_CL = 4
 
int I_CR = 8
 
int I_INSIDE = 16
 
int I_COVERED = 32
 
int I_MODES = 63
 
int MERGE_RUNS = 256
 
int CLIP_RUN = 512
 
int COMBI_MODES = 768
 
int[][] grid
 
BasicStroke pen_1_0 = new BasicStroke(1, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)
 
BasicStroke pen_2_0 = new BasicStroke(2, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)
 
BasicStroke pen_3_0 = new BasicStroke(3, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)
 
BasicStroke pen_4_0 = new BasicStroke(4, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND)
 

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

org.gamecontrolplus.gui.MTimer.MTimer ( 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

Member Function Documentation

void org.gamecontrolplus.gui.MTimer.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
void org.gamecontrolplus.gui.MTimer.fireEvent ( )
protected

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

int org.gamecontrolplus.gui.MTimer.getInitialDelay ( )

Get the initial delay time (milliseconds).

Returns
initial delay in millsecs or -1 if the timer failed to be created.
int org.gamecontrolplus.gui.MTimer.getInterval ( )

Get the interval time (milliseconds) between events.

Returns
interval in millsecs or -1 if the timer failed to be created.
boolean org.gamecontrolplus.gui.MTimer.isRunning ( )

Is the timer running?

Returns
true if running
boolean org.gamecontrolplus.gui.MTimer.isValid ( )

See if the GTimer object has been created successfully

Returns
true if successful
void org.gamecontrolplus.gui.MTimer.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
void org.gamecontrolplus.gui.MTimer.setInitialDelay ( int  initDelay)

Set the delay before the first event is triggered

Parameters
initDelayinitial delay in milliseconds
void org.gamecontrolplus.gui.MTimer.setInterval ( int  interval)

Set the interval between events

Parameters
intervaldelay between events in milliseconds
void org.gamecontrolplus.gui.MTimer.start ( )

Start the timer (call the method forever)

void org.gamecontrolplus.gui.MTimer.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
nrepeats
void org.gamecontrolplus.gui.MTimer.stop ( )

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