On Aug 6, 2012, at 1:10 PM, Luís de Sousa wrote:

> There is an issue with this solution, the draw method keeps being
> invoked even after the object has been stopped. At the moment I'm
> setting up a flag in the stop method that is checked in the draw
> method. It works, but it is not very elegant. Why is the draw method
> invoked even after step has been nullified? Is there any way to
> prevent it?

stop() is with respect to agents (things that are Steppable).  Drawing is with respect to objects (things which appear in fields).  These two things do not at all have to be the same, though they can be.

The drawing facility is drawing your object because it still exists in the physical world, and so when the window has to be drawn, it's going to ask the object to draw and explain itself.  That you had also scheduled it on the schedule as a Steppable is an orthogonal issue.

In fact, even after the simulation has *ended*, as long as you have objects present in the physical world, whenever the window is resized or certain other GUI events occur, the draw() method may *still* be called to redraw them.

You should *always* redraw your objects.  If you don't want them drawn, remove them from your field.  If you'd like them to draw themselves with some default color indicating that they're "stopped", you could do that.