 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Chris Goedde Guest
|
Posted: Sat Nov 29, 2003 10:40 pm Post subject: Need help with layered animation in Swing |
|
|
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
[email]goedde (AT) cascade (DOT) phy.depaul.edu[/email]
|
|
| Back to top |
|
 |
Roedy Green Guest
|
Posted: Sat Nov 29, 2003 11:12 pm Post subject: Re: Need help with layered animation in Swing |
|
|
On 29 Nov 2003 16:40:22 -0600, [email]cgoedde (AT) condor (DOT) depaul.edu[/email] (Chris
Goedde) wrote or quoted :
| Quote: | 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.
|
|
| Back to top |
|
 |
Andrew Thompson Guest
|
Posted: Sat Nov 29, 2003 11:16 pm Post subject: Re: Need help with layered animation in Swing |
|
|
"Chris Goedde" <cgoedde (AT) condor (DOT) depaul.edu> wrote
....
| Quote: | I'm new to java and Swing,
|
If you are new to Java, you should be sometime
off your first Swing programs.
| Quote: | 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
|
|
| Back to top |
|
 |
Chris Goedde Guest
|
Posted: Sun Nov 30, 2003 12:03 am Post subject: Re: Need help with layered animation in Swing |
|
|
Roedy Green (see mindprod.com) wrote:
| Quote: | On 29 Nov 2003 16:40:22 -0600, [email]cgoedde (AT) condor (DOT) depaul.edu[/email] (Chris
Goedde) wrote or quoted :
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.
|
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.
--
Chris Goedde
[email]cgoedde (AT) condor (DOT) depaul.edu[/email]
|
|
| Back to top |
|
 |
Roedy Green Guest
|
Posted: Sun Nov 30, 2003 12:53 am Post subject: Re: Need help with layered animation in Swing |
|
|
On 29 Nov 2003 18:03:21 -0600, [email]cgoedde (AT) condor (DOT) depaul.edu[/email] (Chris
Goedde) wrote or quoted :
| Quote: | 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.
|
|
| Back to top |
|
 |
Knute Johnson Guest
|
Posted: Sun Nov 30, 2003 6:36 pm Post subject: Re: Need help with layered animation in Swing |
|
|
Chris Goedde wrote:
| Quote: | Roedy Green (see mindprod.com) wrote:
On 29 Nov 2003 16:40:22 -0600, [email]cgoedde (AT) condor (DOT) depaul.edu[/email] (Chris
Goedde) wrote or quoted :
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.
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.
|
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.
--
Knute Johnson
email s/nospam/knute/
Molon labe...
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|