BBjAPI::createTimer

Description

In BBj 3.00 and higher, this method creates a timer, which calls a method on a UserObject at a specified interval.

Syntax

Return Value

Method

void

createTimer(Object key, number seconds, string label)

void

createTimer(Object key, number seconds, UserObject obj, string methodName)

Parameters

Variable

Description

key

A unique key that identifies the timer. If numeric, the key will be returned in field y of the event string (see Timer Event).

label

The subroutine to be invoked when the timer fires.

seconds

Specifies the timeout value in seconds. Fractional seconds are allowed to millisecond resolution, but a very small timeout value will cause a flood of events faster than the program can respond to them.

obj

A UserObject containing the method to be called when the timer fires.

methodName

The name of the method that is to be called when the timer fires.

Return Value

None.

Remarks

When registering a UserObject method as the target of the callback, the method must conform to the following constraints:

  • The method must be declared as public with a return type of void.

  • The method must accept a single parameter.

The type of the method parameter must be either BBjTimerEvent or BBjEvent or java.lang.Object.

To eliminate the timer, see removeTimer.

Example

rem 'Timer event

SYSGUI = UNT
OPEN (SYSGUI)"X0"
bbj! = BBjAPI()
sysgui! = bbj!.getSysGui()
window! = sysgui!.addWindow(100,100,200,200,"Timer Test")
CALLBACK(ON_CLOSE,APP_CLOSE,sysgui!.getContext())
bbj!.createTimer(1,1,"one")
bbj!.createTimer("ten seconds",10,"ten")
bbj!.createTimer(20,20,"twenty")
process_events

APP_CLOSE:
    ESCAPE

one:
    print "second timer"
return

ten:
    print "10 second timer"
return

twenty:
    print "20 second timer"
    bbj!.removeTimer(20)
return

See Also

Timer Event

BBjAPI

BBjAPI::removeTimer

See the BBj Object Diagram for an illustration of the relationship between BBj Objects.