Need help with layered animation in Swing

From: Chris Goedde (cgoedde_at_condor.depaul.edu)
Date: 11/29/03


Date: 29 Nov 2003 16:40:22 -0600

Hi all,

I'm new to java and Swing, and I have some questions about doing a
particular animation.

I'm trying to animate a phase portrait, which is a representation of
the motion of an oscillator (think of a pendulum). One axis of the
portrait is the position of the oscillator (the angle of the pendulum)
and the other is the speed of the oscillator. My app numerically finds
the motion of the oscillator, which may be quite complex (if the
motion is chaotic, for example). The phase portrait is a series of
points that show a record of the motion of the oscillator. (Unanimated
phase portraits can be seen at http://mathworld.wolfram.com/PhaseCurve.html)

I have a JFrame that I can draw the coordinate axes on. On top of that
I'd like to paint two things: an animated marker (e.g. a circle or
some other shape) showing the (changing) current point in the phase
portrait, and a sequence of points showing the history of the motion.
I can easily do all of these things individually, but I'm having
trouble putting them together. In other words, the marker is animated
across the coordinate axes, and leaves a trail of points in its wake.

My question is sort of general, because I'm not sure if I near or far
from a solution. I'm trying to build this up out of subclasses of
JPanels placed in a JLayeredPane, where I override the paintComponent
method of each JPanel to draw a layer (either axes, or marker, or
history) of the portrait. But I don't understanding painting in Swing
well enough to know if this approach will or even can work.

So my question is, how should I approach this problem? Any pointers
or suggestions would be greatly appreciated.

Thanks,

-- 
Chris Goedde
goedde@cascade.phy.depaul.edu