Results 1 to 2 of 2
- 02-11-2011, 02:16 AM #1
Member
- Join Date
- Feb 2011
- Posts
- 1
- Rep Power
- 0
How to get a normally-repeating gif to only display once
I am working on a game using Swing for the GUI, and part of the dialog requires a 'surprised' sprite gif to run.
I have the normal talking gif in a JLabel, and can replace it with the 'surprised' gif, but I am unable to find a way to have it only display once. I have thought about getting each frame as rotating still jpg's or png's and then using the display time between the gif's frames, but I cannot find a way to get the display times, and it would be a terrible amount of work.
Also, if I could find a value of the total length of the gif, I might be able to let the rest of the thread Sleep for that length while it runs.
If any of these solutions is possible, it would be great for you to help. Thanks.Last edited by Enterprize; 02-11-2011 at 02:21 AM. Reason: Added detail
- 02-11-2011, 05:57 AM #2
In regards to doing it frame by frame (thats what I do) it isn't hard at all. the javax.swing.Timer is made for this reason!
You can do something like this:
Make sense?Java Code:public void Animate() { //250ms refresh rate Timer t = new Timer(250, new ActionListener() { public void actionPerformed(ActionEvent e) { advanceFrame(); } }); t.start(); } int currentFrame = 0; //Initialize this with ImageIO to load the frames BufferedImage[] frames; private void advanceFrame() { if(currentFrame < frames.length-1){ currentFrame++; } else{ currentFrame = 0; } } }
Similar Threads
-
jxl repeating rows
By mermaid in forum New To JavaReplies: 0Last Post: 01-14-2011, 03:59 PM -
Repeating
By AbdulAziz Bader in forum New To JavaReplies: 3Last Post: 05-05-2010, 11:35 PM -
Repeating Do-While Statement
By adamg106 in forum New To JavaReplies: 10Last Post: 04-22-2010, 07:09 AM -
Non-Repeating Random Integers
By Psyclone in forum New To JavaReplies: 5Last Post: 01-31-2010, 09:04 PM -
adjacent repeating letters
By artemis_r2 in forum New To JavaReplies: 1Last Post: 11-17-2007, 04:48 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks