2013-01-04 4 views
0

Possible en double:
Show animated gif in JavaComment insérer une image GIF animée en Java

Comment puis-je insérer une image GIF animée en Java?

J'ai déjà regardé différentes réponses et questions. Mais quand je code ceci, il ne montre pas le gif animé.

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

En fin de compte, j'utilise la méthode drawImage.

Répondre

4

Vous pouvez simplement utiliser un JLabel (volé de here, vont lui donner crédit si c'est ce que vous avez besoin.)

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

est un groupe clignote à la différence du GIF d'origine. Une idée pourquoi? –

Questions connexes