0

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:

Resulting Window

Any help whatsoever is highly appreciated.

-Defalt

Community
  • 1
  • 1
The Defalt
  • 69
  • 8
  • 1
    Is it possible that the image path is wrong? Replace `%2F` for `/` so that you have [http://i.imgur.com/TdRNfPP.jpg](http://i.imgur.com/TdRNfPP.jpg) – kazbeel Jun 20 '16 at 07:30
  • Thank you sir, but the result is the same. EDIT: Actually, that did work! I made a typo and caught it after I compiled and ran. Thank you sir. – The Defalt Jun 20 '16 at 07:32
  • The code seems to be correct. Perhaps the problem is in the image file extension. It's supposed to be a GIF but the extension is JPG. – kazbeel Jun 20 '16 at 07:36

0 Answers0