|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.cycling74.max.Callback
public class Callback
Callback
is an implementation of the Executable interface.
One could use an instance of Callback
as part of the constructor
for a MaxClock
or MaxQelem
as follows:
public class callbacktest extends MaxObject { private static final double DELAY_TIME = 500.; private Callback cb; private MaxClock cl; callbacktest() { cb = new Callback(this, "daBomb"); cl = new MaxClock(cb); } public void bang() { cl.delay(DELAY_TIME); } private void daBomb() { post("bOOm!"); cl.delay(DELAY_TIME); } }
Callback
it is possible to define a parameter list
so that something like MaxClock
or MaxQelem
can be made to
call a method that takes parameters. Furthermore, one can
alter the parameters at anytime. For instance:
public class Callbacktest extends MaxObject {
private static final double DELAY_TIME = 500.;
private Callback cb;
Callback
e MaxClock cl;
callbacktest() {
cb = new Callback(this, "daBomb", true);
cl = new MaxClock(cb);
}
public void bang() {
cl.delay(DELAY_TIME);
}
private void daBomb(boolean b) {
if (b)
post(" is da bomb!");
else
post("not da bomb."):
cb.setArgs(!b);
cl.delay(DELAY_TIME);
}
}
created on 5-May-2004
Constructor Summary | |
---|---|
Callback(java.lang.Object o,
java.lang.String methodname)
creates a Callback object for an executing method with no arguments |
|
Callback(java.lang.Object o,
java.lang.String methodname,
boolean b)
creates a Callback object for an executing method with one boolean argument |
|
Callback(java.lang.Object o,
java.lang.String methodname,
float f)
creates a Callback object for an executing method with one float argument |
|
Callback(java.lang.Object o,
java.lang.String methodname,
int i)
creates a Callback object for an executing method with one int argument |
|
Callback(java.lang.Object o,
java.lang.String methodname,
java.lang.Object[] argObjectArray)
creates a Callback object for an executing method with a
parameter list represented by the Object array argObjectArray. |
|
Callback(java.lang.Object o,
java.lang.String methodname,
java.lang.Object[] argObjectArray,
java.lang.Class[] argClassArray)
creates a Callback object for an executing method with
a parameter list represented by the Object array argObjectArray
and with Class list argClassArray. |
|
Callback(java.lang.Object o,
java.lang.String methodname,
java.lang.String s)
creates a Callback object for an executing method with one String argument |
Method Summary | |
---|---|
void |
execute()
executes the method associated with the Callback . |
java.lang.Object[] |
getArgs()
Gets the current parameters that will be passed to the executing method. |
java.lang.reflect.Method |
getMethod()
Gets the executing method. |
java.lang.String |
getMethodName()
Gets the name of the executing method. |
java.lang.Object |
getObject()
Gets the Object that contains the executing method. |
void |
setArgs(boolean b)
Set the argument for an executing method that takes a boolean. |
void |
setArgs(float f)
Set the argument for an executing method that takes a float. |
void |
setArgs(int i)
Set the argument for an executing method that takes an integer. |
void |
setArgs(java.lang.Object[] a)
Set the argument array for an executing method. |
void |
setArgs(java.lang.String s)
Set the argument for an executing method that takes a String. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Callback(java.lang.Object o, java.lang.String methodname)
Callback
object for an executing method with no arguments
o
- object that contains the executing methodmethodname
- name of the executing methodpublic Callback(java.lang.Object o, java.lang.String methodname, int i)
Callback
object for an executing method with one int argument
o
- object that contains the executing methodmethodname
- name of the executing methodi
- the integer to pass as an argument to the executing methodpublic Callback(java.lang.Object o, java.lang.String methodname, float f)
Callback
object for an executing method with one float argument
o
- object that contains the executing methodmethodname
- name of the executing methodf
- the float to pass as an argument to the executing methodpublic Callback(java.lang.Object o, java.lang.String methodname, java.lang.String s)
Callback
object for an executing method with one String argument
o
- object that contains the executing methodmethodname
- name of the executing methods
- the String to pass as an argument to the executing methodpublic Callback(java.lang.Object o, java.lang.String methodname, boolean b)
Callback
object for an executing method with one boolean argument
o
- object that contains the executing methodmethodname
- name of the executing methodb
- the boolean value to pass as an argument to the executing methodpublic Callback(java.lang.Object o, java.lang.String methodname, java.lang.Object[] argObjectArray)
Callback
object for an executing method with a
parameter list represented by the Object array argObjectArray.
Note that primitive types (boolean
, char
,
byte
, short
, int
, long
,
float
, double
)
are not supported by this method - the corresponding wrapper objects
(Boolean
, Char
, Byte
, Short
,
Integer
, Long
, Float
, Double
)
must be used.
To mix objects and primitive types, please refer to
Callback(Object, String, Object[], Class[])
.
o
- object that contains the executing methodmethodname
- name of the executing methodargObjectArray
- the object array to pass as an argument to the executing methodpublic Callback(java.lang.Object o, java.lang.String methodname, java.lang.Object[] argObjectArray, java.lang.Class[] argClassArray)
Callback
object for an executing method with
a parameter list represented by the Object array argObjectArray
and with Class list argClassArray.
By specifying the Class array explicitly, this method allows you to pass
primitive types as arguments. To enable one of the primitive types
(boolean
, char
,
byte
, short
, int
, long
,
float
, double
) as an
element of the argument array, that element of argObjectArray
must be set to the corresponding wrapper Object (Boolean
, Char
, Byte
, Short
,
Integer
, Long
, Float
, Double
)
with the value of the primitive type, and the element
of the argClassArray must be set to the special corresponding Class object
that is set up to represent the primitive as an Class (java.lang.Boolean.TYPE
,
java.lang.Character.TYPE
, java.lang.Byte.TYPE
,
java.lang.Short.TYPE
, java.lang.Integer.TYPE
,
java.lang.Long.TYPE
, java.lang.Float.TYPE
,
java.lang.Double.TYPE
).
Callback
that executes a method that takes an int and an Atom
array as
parameters.
public class CallbackExample extends MaxObject { private static final DELAY_TIME = 500.; Callback cb; MaxClock ck; CallbackExample(Atom[] initArgs) { cb = new Callback(this, "doThis", new Object[] {new Integer(1), initArgs}, new Class[] {java.lang.Integer.TYPE, initArgs.getClass()}); ck = new MaxClock(cb); } public void bang() { ck.delay(DELAY_TIME); } private method doThis(int i, Atom[] a) { // do stuff } }
o
- object that contains the executing methodmethodname
- name of the executing methodargObjectArray
- the object array to pass as an argument to the executing methodargClassArray
- the class array that defines the classes of the argumentMethod Detail |
---|
public void setArgs(int i)
Callback
to fail if the
Callback
was not constructed with a single int parameter!
i
- the new value to pass the executing methodpublic void setArgs(float f)
Callback
to fail if the
Callback
was not constructed with a single float parameter!
f
- the new value to pass the executing methodpublic void setArgs(boolean b)
Callback
to fail if the
Callback
was not constructed with a single boolean parameter!
b
- the new value to pass the executing methodpublic void setArgs(java.lang.String s)
Callback
to fail if the
Callback
was not constructed with a single String parameter!
s
- the new value to pass the executing methodpublic void setArgs(java.lang.Object[] a)
Callback
will fail!
a
- the new array to pass as an argument to the executing methodpublic void execute()
Callback
.
execute
in interface Executable
Executable.execute()
public java.lang.Object[] getArgs()
MaxClock
, you could
do something like this:
public manipulateArgs(Callback cb) { Object[] paramObjs = c.getArgs; if (paramObjs.length > 0) { int i = ((Integer)paramObjs[0]).intValue(); float f = ((Float)paramObjs[1]).floatValue(); MaxClock cl = (MaxClock)paramObjs[2]; // now do stuff with the variables... } }
public java.lang.Object getObject()
public java.lang.reflect.Method getMethod()
public java.lang.String getMethodName()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |