> MonsterTask.run() must be returning something besides
> Monster.toString(), obviously. How can MonsterTask.run() return "this"
[quoted text clipped - 3 lines]
>
> Thufir Hawat
Currently, a MonsterTask knows nothing of a Monster. So you'll have to
tie them somehow together. Does a MonsterTask always belong to one
Monster ("One MonsterTask manages one Monster")? If so, this can be
modeled by creating an instance variable (aka field, or member variable)
of type Monster in Monstertask, and assigning it properly.

Signature
Regards,
Roland de Ruiter
___ ___
/__/ w_/ /__/
/ \ /_/ / \
thufir - 29 Jan 2005 12:11 GMT
[..]
> Currently, a MonsterTask knows nothing of a Monster. So you'll have to
> tie them somehow together. Does a MonsterTask always belong to one
> Monster ("One MonsterTask manages one Monster")? If so, this can be
> modeled by creating an instance variable (aka field, or member variable)
> of type Monster in Monstertask, and assigning it properly.
[..[
I think I follow you, but am drawing a blank on how to implement it. A
Monster instance reference needs to be passed; what reference gets
passed and to which method?
How can output like "monster one running" be periodically generated?
It seems that MonsterTask needs to reference a Monster instance...
thanks,
Thufir Hawat
///////////////////////////MonsterTask/////
package atreides.monsters;
public class MonsterTask
extends java.util.TimerTask{
public void run() {
System.out.println( "..run" );
}//run
}//MonsterTask
///////////////////////////Monster////////
package atreides.monsters;
public class Monster{
java.util.Timer timer = new java.util.Timer();
java.util.TimerTask task = new MonsterTask();
private static java.util.List<MonsterItem> list;
private java.util.Date timeStamp;
private int monsterNumber = 0;
public Monster(int i){
timeStamp = new java.util.Date();
monsterNumber = i;
list = new java.util.ArrayList<MonsterItem>();
}//Monster
public void setTimerPeriod(long period, Monster aMonster){
period = 2000;
long lag = 1000;
timer.schedule( task, lag, period );
}//setTimerPeriod
public String toString(){
return "\n\t..toString..\t" + timeStamp +
"\n\t monsterNumber\t" + monsterNumber;
}//toString
}//Monster