We help IT Professionals succeed at work.
Get Started

GAME MAKING Adding animated GIFs to JFrame - how do I move them?

793 Views
Last Modified: 2013-11-23
Hi, I am making a game.

I am using an animated GIF of a mutalisk to get me started on animated enemies / targets.

I tried it in an applet, but couldnt do double buffering. It was also a little slow for my needs.

So I am back to JFrame.
I can add the mutalisk to a JFrame content pane (attached) but I cant get a handle on its position  (x,y)  to move it around.
Any ideas? Plz See my code...

import java.awt.*;
import java.net.*;
import javax.swing.*;
 
public class Anima {
    public static void main(String[] args) throws MalformedURLException {
 
    	System.out.println("New Main");
        URL url = new URL("http://www.jamescomp.com/pics/mutalisk.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);
    }
}

Open in new window

Comment
Watch Question
Java Developer
CERTIFIED EXPERT
Top Expert 2010
Commented:
This problem has been solved!
Unlock 3 Answers and 6 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE