2013-01-04 203 views
0

可能重复:
Show animated gif in Java如何插入GIF动画在Java中

我如何可以插入Java中的动画GIF图像?

我已经看过不同的答案和问题。但是当我编码时,它不会显示GIF动画。

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

最后,我用方法drawImage

回答

4

你可以简单地使用一个JLabel(从here被盗,去给他的信用,如果这是你需要的东西。)

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); 
} 
+0

是闪烁一堆不像原来的gif。任何想法为什么? –