I found a GIF I want to add into one of my Java programs. When I run it the picture shows up and works, but it leaves a trail behind it (it isn't actually replacing the white behind the picture) and the window is incorrectly sized. I searched before but nothing fixed it.
package tasks;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class duane
{
public static void main(String[] args) throws MalformedURLException {
URL url = new URL("http://i2.kym-cdn.com/photos/images/newsfeed/000/602/307/4d3.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);
}
}
What would I add in to make the window the correct size and how would I repaint it?