simulator.start();
Rectangle b = simulator.getBounds();
DesktopScreenRegion smallRegion = new DesktopScreenRegion(b.x, b.y, b.width, b.height);
TargetEventListener l = new TargetEventListener(){
@Override
public void targetAppeared(TargetEvent event) {
System.out.println(event.getTarget() + " has appeared within " + event.getScreenRegion() +
" at " + Relative.to(event.getTargetRegion()).topLeft().getScreenLocation());
canvas.clear().addBox(event.getTargetRegion());
canvas.addLabel(event.getTargetRegion(),"appeared");
canvas.display(1);
}
@Override
public void targetVanished(TargetEvent event) {
System.out.println(event.getTarget() + " has vanished from " + event.getScreenRegion());
canvas.clear().addBox(event.getTargetRegion());
canvas.addLabel(event.getTargetRegion(),"vanished");
canvas.display(1);
}
@Override
public void targetMoved(TargetEvent event) {
System.out.println(event.getTarget() + " has moved to " +
Relative.to(event.getTargetRegion()).topLeft().getScreenLocation());
canvas.clear().addBox(event.getTargetRegion());
canvas.addLabel(event.getTargetRegion(),"moved");
canvas.display(1);
}
};
// watch the dog and the cat in the screen region
Target cat = new ImageTarget(Images.Cat);
Target dog = new ImageTarget(Images.Dog);
smallRegion.addTargetEventListener(dog, l);
smallRegion.addTargetEventListener(cat, l);
}