I've recently begun learning Java. I've taken the usual approach that I take, to dissect other code and learn how it works. My first goal is to simply animate a GIF, but I can't make heads or tails of this problem.
I followed the answer in this question. But when I compile and run the program, I get a blank window. This window does have the title assigned to it, but with no GIF inside. Here is my current code:
import javax.swing.*;
import java.net.URL;
import java.net.MalformedURLException;
class giftest {
public static void main(String[] args) throws MalformedURLException {
URL url = new URL("http://i.imgur.com%2FTdRNfPP.jpg");
Icon icon = new ImageIcon(url);
JLabel label = new JLabel(icon);
JFrame f = new JFrame("j0in Dedsec!");
f.getContentPane().add(label);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
}
I get no errors when compiling or running this code, and here is a screenshot of the window that shows:
Any help whatsoever is highly appreciated.
-Defalt