java applet animated gifs..

I noticed that animated Gifs appear distorted when put in an applet,( at least in my experience).. Is this a bad way to animate inside java applets? Is there a prefferred way?
[182 byte] By [Conquerana] at [2007-10-3 8:10:13]
# 1
Define distorted. I wasn't even a aware J2SE supported animated images without some massaging.
kablaira at 2007-7-15 3:14:34 > top of Java-index,Java Essentials,Java Programming...
# 2
Ive seen animated gifs in an applet before (although Ive never done it myself) and they didnt look distorted.
CaptainMorgan08a at 2007-7-15 3:14:34 > top of Java-index,Java Essentials,Java Programming...
# 3

Someone asked about animated icons on the Java2D list and this link popped up:

http://rabbit-hole.blogspot.com/2006/09/animated-icon-redux.html

That may help you. I don't know, you haven't really said what you mean by "distorted" or told us how you're loading and displaying the animated GIF.

kablaira at 2007-7-15 3:14:34 > top of Java-index,Java Essentials,Java Programming...
# 4

I've put animated gifs in applets plenty of times and it worked fine. No "distortion". Actually not only did it work fine, but it was easy -- you just use drawImage like you would with any other image, and repaint() frequently, and the GUI toolkit figured out how to select frames for animation. I didn't even have to do the animation part.

paulcwa at 2007-7-15 3:14:34 > top of Java-index,Java Essentials,Java Programming...
# 5

> I've put animated gifs in applets plenty of times and

> it worked fine. No "distortion". Actually not only

> did it work fine, but it was easy -- you just use

> drawImage like you would with any other image, and

> repaint() frequently, and the GUI toolkit figured out

> how to select frames for animation. I didn't even

> have to do the animation part.

It's not quite that simple though. Depending on how the image is loaded that may or may not actually work. For example, one of these draws the animation perfectly, the other doesn't:

JFrame frame = new JFrame();

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.add(new JLabel(new ImageIcon("C:\\anim.gif")));

frame.pack();

frame.setVisible(true);

JFrame frame = new JFrame();

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.add(new JLabel(new ImageIcon(ImageIO.read(new File("C:\\anim.gif"))));

frame.pack();

frame.setVisible(true);

kablaira at 2007-7-15 3:14:34 > top of Java-index,Java Essentials,Java Programming...
# 6

import java.awt.*;

import java.applet.*;

// These classes are for Url's.

import java.net.*;

public class finding extends Applet

{

Image image;

URL base;

public void init()

{

base = getDocumentBase();

image = getImage(base,"finding.gif");

}

public void paint( Graphics g )

{

g.drawImage( image, 0, 0, this );

}

}

//////////////////////////////////////

this is what I did.. The image animates but it flashes across the screen... it isnt smooth animation.. I made the program as simple as I could..

Conquerana at 2007-7-15 3:14:34 > top of Java-index,Java Essentials,Java Programming...
# 7
> this is what I did.. The image animates but it> flashes across the screenIt might be a double-duffering issue.
CaptainMorgan08a at 2007-7-15 3:14:34 > top of Java-index,Java Essentials,Java Programming...