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,

Signature
Chris Goedde
goedde@cascade.phy.depaul.edu
Roedy Green - 29 Nov 2003 23:12 GMT
>So my question is, how should I approach this problem? Any pointers
>or suggestions would be greatly appreciated.
Compose a PaintComponent that can draw the situation at time t.
use a swing.Timer to trigger a repaint event on a periodic basis.
PaintCompontent then wakes up, increments t and paints and quits.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Chris Goedde - 30 Nov 2003 00:03 GMT
>>So my question is, how should I approach this problem? Any pointers
>>or suggestions would be greatly appreciated.
[quoted text clipped - 4 lines]
>
>PaintCompontent then wakes up, increments t and paints and quits.
Thanks for the reply, I've gotten that far.
I'll ask a more specific question.
Right now I have the axes drawn in a JPanel in one layer of a
JLayeredPane, and the points drawn in a JPanel with a transparent
background that sits above this layer. How do I get Swing to only
repaint the upper layer, and not the lower layer? Right now, all my
attempts end up redrawing both, so the background gets redrawn over
the upper layer, obliterating the trail of points, so I just see a
single animated point, rather than a trail of points.

Signature
Chris Goedde
cgoedde@condor.depaul.edu
Roedy Green - 30 Nov 2003 00:53 GMT
> Right now, all my
>attempts end up redrawing both, so the background gets redrawn over
>the upper layer, obliterating the trail of points, so I just see a
>single animated point, rather than a trail of points.
You pretty much have to track the trail of points yourself and redraw
them on command. Remember that in theory some other app could occlude
yours and then reveal it.
Put the points in an ArrayList of Points.
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
Knute Johnson - 30 Nov 2003 18:36 GMT
>>>So my question is, how should I approach this problem? Any pointers
>>>or suggestions would be greatly appreciated.
[quoted text clipped - 16 lines]
> the upper layer, obliterating the trail of points, so I just see a
> single animated point, rather than a trail of points.
One other option might be to consider using a BufferedImage as your
record. Don't clear it between draws and your points will still be there.

Signature
Knute Johnson
email s/nospam/knute/
Molon labe...
Andrew Thompson - 29 Nov 2003 23:16 GMT
...
> I'm new to java and Swing,
If you are new to Java, you should be sometime
off your first Swing programs.
> and I have some questions about doing a
> particular animation.
...
> So my question is, how should I approach this problem? Any pointers
> or suggestions would be greatly appreciated.
Start with 'HelloWorld.java' and follow a progressive
and gradual path toward GUI development.
--
Andrew Thompson
* http://www.PhySci.org/ PhySci software suite
* http://www.1point1C.org/ 1.1C - Superluminal!
* http://www.AThompson.info/andrew/ personal site