2

I was just wondering how to use animated GIFs in my program (right now I'm just using PNGs). I just want to be able to cycle through the different pictures in the GIFs, but I don't know the classes to use.

What classes are used to load and display animated GIFs?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Jimmt
  • 852
  • 2
  • 11
  • 29

1 Answers1

8
new JLabel( new ImageIcon( URL ) );

E.G.

ShowAnimatedGif Star Zoom

import javax.swing.*;
import java.net.URL;

class ShowAnimatedGif {

    public static void main(String[] args) throws Exception {
        final URL url = new URL("http://pscode.org/media/starzoom-thumb.gif");
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                JLabel l = new JLabel(new ImageIcon(url));
                JOptionPane.showMessageDialog(null, l);
            }
        });
    }
}
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • I in-lined the animated GIF just in case my pscode.org site ever disappears. The direct link to the version embedded at SO (edit the URL in the source) is http://i.stack.imgur.com/4zxj9.gif – Andrew Thompson Jan 22 '12 at 04:10
  • [I'm re_posted your nice idea](http://www.daniweb.com/software-development/java/threads/416639/1777566#post1777566) – mKorbel Mar 09 '12 at 17:46