Previous Topic Tutorial Home Page Next Topic
Interacting with geoImage


This class produces a bidirectional counter that cycles in a given range upon button presses.
class Counter extends Statics implements UntilNotifier {

constructor for a counter object
public Counter(NumberBvr limit) {
_counterLimit = limit;

upon a skip event invoke the notifier
_value = (NumberBvr)untilNotify(_initValue, skip, this);
}

public Behavior notify(Object eventData, Behavior previous, BvrsToRun lst) {

extract the application data (an integer), into a number behavior
NumberBvr adjustment = toBvr(((Integer)eventData).intValue());

use it as an inc/decrement
NumberBvr value = add((NumberBvr)previous, adjustment);

cycle between 0 and (limit - 1)
value = (NumberBvr)cond(eq(value, toBvr(-1)),
sub(_counterLimit, toBvr(1)),
if -1, wrap around
cond(eq(value, _counterLimit), toBvr(0), value));
if limit, wrap around
repeat with the new value
return untilNotify(value, skip, this);
}

public NumberBvr getBvr () {
return _value;
}

Key events with corresponding event data. For non-ASCII keys use the Java designation for the key.
private static final DXMEvent skipForward1 = keyDown(Event.RIGHT).attachData(new Integer(1));
private static final DXMEvent skipBack1 = keyDown(Event.LEFT).attachData(new Integer(-1));

For ASCII keys use the ASCII letter between single quotes.
private static final DXMEvent skipForward2 = keyDown(' ').attachData(new Integer(1));

There is also a timeout event for automatically switching between pictures if no manual key presses are issued.
private static final DXMEvent auto = timer(toBvr(8)).attachData(new Integer(1));

Aggregate the four events above into a single event.
private static final DXMEvent skip = orEvent(skipForward1,
orEvent(skipBack1,
orEvent(skipForward2, auto)));

These are aspects of the counter.
private NumberBvr _counterLimit;
private NumberBvr _initValue = toBvr(0);
start counting at 0
private NumberBvr _value;
current value of counter

}

© 1998 Microsoft Corporation. All rights reserved. Terms of Use.

Previous Topic Tutorial Home Page Next Topic