0

Possible Duplicate:
Show animated gif in Java

How can I insert an animated gif image in Java?

I have already looked at different answers and question. But when I code this, it doesn't show the gif animated.

Image image = Toolkit.getDefaultToolkit().getImage("yourFile.gif");
Image image=ImageIO.read(new File("yourFile.gif"));

In the end, I use the method drawImage.

Community
  • 1
  • 1
Kamj Duong
  • 135
  • 1
  • 3
  • 10

1 Answers1

4

You could simply use a JLabel (Stolen from here, go give him credit if this is what you needed.)

public static void main(String[] args) throws MalformedURLException {

    URL url = new URL("<URL to your Animated GIF>");
    Icon icon = new ImageIcon(url);
    JLabel label = new JLabel(icon);

    JFrame f = new JFrame("Animation");
    f.getContentPane().add(label);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.pack();
    f.setLocationRelativeTo(null);
    f.setVisible(true);
}
Community
  • 1
  • 1
Mike
  • 2,434
  • 1
  • 16
  • 19