Re: Animation Problem
Stefan Ram wrote:
The behavior of paintComponent() depends on whether this
is a continous animation depending on the time or a
stepped calculation proceeding in generations. In the
first case, the picture is calculated for the current time.
In the second case, the next generation is calculated
and then display. Both of which, however, might conflict
recommendations not to do long calculations within the
event-dispatch thread (I don't know how to handle this).
Not the next generation of plumbing plastic, the answer to all things Swing is
The state of the animation, generational or time-based, is the model. (Well,
one of them.) It is calculated off the EDT. On its own thread (group). Not
on the EDT.
Periodically the EDT wakes up and dips in to the model waters for a refreshing
draught of visible results. It requests model state for purposes of painting.
If the model is generational then the view (that's the part on the EDT) just
takes a snapshot of whatever generation is ready, and preps it for
paintComponent(), or repaint(), or whatever.
If the model is time-based, you probably need some event stitching. Well,
events help the generational model, too.
Anyway, the animation model runs as fast as desired, or as close as possible,
in its own thread.
Perhaps the animation runs a frame at a time, based on a javax.util.Timer
telling it when it's time to make another frame. Maybe it runs at odd times
depending on when another logic model fires an event. Maybe it runs on demand
when the view asks for an update, again possibly using event notification to
make that happen. Maybe the animation model fires events when it has done
something important (e.g., completed a frame). (I'm a little suspicious of
approaches where the animation model pushes rather than having the view pull.
I don't know if that suspicion is rational - I'll have to investigate when I
have some time. We could have a subthread on that.)
Note that by this approach the animation model is decoupled from the view, the
timing engine and other logic models, both conceptually and operationally.