Skip to main content

[JAVA2D] Simple way to animate an image sequence on a JPanel ?

1 reply [Last post]
Anonymous

Hi everyone,

I would like to display a sequence of Image on a JPanel at a given
frame rate (around 30 fps). Right now I am doing this the
"not-so-subte" way:

destinationJPanel.getGraphics().drawImage(imageToDisplay,
horizontalOffset, verticalOffset, this);

In othe words, every time my timing controller tells me it is time to
update the display, I invoke the code above.

This works, however there are strong disadvantages in updating the
panel using such a "brutal" approach: the menus which are placed right
above the panel are unusable. When I try opening one of these menus,
the "drop down" list of options is "hidden" by the frames I draw.

I know I should be using some kind of double buffering but how should
I implement that ?

D.

PS: I'm stuck with jdk 1.4.2 for now so I won't be able to use any of
the nifty new features in Java 5 :-(

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Ted Hill

See chapter two of

Killer Game Programming in Java

For examples and discussion of exactly this topic.

http://www.oreilly.com/catalog/killergame/toc.html

-----Original Message-----
From: Discussion list for Java 2D API
[mailto:JAVA2D-INTEREST@JAVA.SUN.COM] On Behalf Of Java Questions
Sent: Friday, June 10, 2005 8:07 AM
To: JAVA2D-INTEREST@JAVA.SUN.COM
Subject: [JAVA2D] Simple way to animate an image sequence on a JPanel ?

Hi everyone,

I would like to display a sequence of Image on a JPanel at a given frame
rate (around 30 fps). Right now I am doing this the "not-so-subte" way:

destinationJPanel.getGraphics().drawImage(imageToDisplay,
horizontalOffset, verticalOffset, this);

In othe words, every time my timing controller tells me it is time to
update the display, I invoke the code above.

This works, however there are strong disadvantages in updating the panel
using such a "brutal" approach: the menus which are placed right above
the panel are unusable. When I try opening one of these menus, the "drop
down" list of options is "hidden" by the frames I draw.

I know I should be using some kind of double buffering but how should I
implement that ?

D.

PS: I'm stuck with jdk 1.4.2 for now so I won't be able to use any of
the nifty new features in Java 5 :-(

========================================================================
===
To unsubscribe, send email to listserv@java.sun.com and include in the
body of the message "signoff JAVA2D-INTEREST". For general help, send
email to listserv@java.sun.com and include in the body of the message
"help".

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".