CS 4773 Object Oriented Systems
RectLineMoveMulti.java
import java.awt.*;
import java.util.*;
public class RectLineMoveMulti extends RectLinePos
implements DelayCallBack {
private int delay;
private MoveCallBack cb;
private DelayThreadMulti dt;
private Vector delayvec;
public RectLineMoveMulti(Point start, Point end, Dimension dim, Color C,
int delay, Vector delayvec, MoveCallBack cb) {
super(start,end,dim,C);
this.delay = delay;
this.delayvec = delayvec;
this.cb = cb;
set_delay_thread();
}
private void set_delay_thread() {
DelayThreadMulti cd;
DelayThreadMulti d;
if (delayvec.size() == 0)
cd = null;
else {
cd = (DelayThreadMulti)delayvec.elementAt(0);
for (int i=1;i Math.abs(d.GetDelay()-delay)) )
cd = d;
}
}
if ( (cd != null) && (Math.abs(cd.GetDelay()-delay) < 10) ) {
dt = cd;
dt.AddCallBack(this);
}
else {
dt = new DelayThreadMulti(delay,this);
delayvec.addElement(dt);
}
}
public void kill() {
dt.kill();
}
public void stop() {
dt.PauseDelay();
}
public void start() {
dt.ContinueDelay(this);
}
public int GetDelay() {
return delay;
}
public void DelayNotification() {
NextPosition();
cb.MoveNotification();
}
public void NextPosition() {
super.NextPosition();
if (isDone())
dt.RemoveEntry(this);
}
}