0

I'm using java 1.5 and want to show an animation before starting my application and close it when my application is loaded. I create something after googleing but animated gif doesn't animate if i use not animated gif it shows up.

Does any body what is the problem and know how to do it?

public class SplashFrameSwing extends JFrame{
JPanel contentPane;
JLabel imageLabel = new JLabel();

public SplashFrameSwing(String url) throws IOException {
    try {
        ImageIcon ii = new ImageIcon(url);
        setBackground(new Color(0, 0, 0, 0));
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        contentPane = (JPanel) getContentPane();
        contentPane.setLayout(new BorderLayout());
        setUndecorated(true);
        setSize(new Dimension(ii.getIconWidth(),ii.getIconHeight()));
        imageLabel.setIcon(ii);
        contentPane.add(imageLabel, java.awt.BorderLayout.CENTER);
        this.setLocationRelativeTo(null);
        this.setVisible(true);
    } catch (Exception exception) {
        exception.printStackTrace();
    }
}

public static void main(String... args){
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            try {
                // URL url = new URL("http://i34.photobucket.com/albums/d129/nirendaran/Speed/verify_anim.gif");
                String url = "C:\\Users\\TV\\Pictures\\Icon\\sniffer-prev.gif";
                SplashFrameSwing splash  = new SplashFrameSwing(url);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });
}
}
itro
  • 7,006
  • 27
  • 78
  • 121
  • In that example, there's a more substantial difference between your two examples, in that the animated one is a remote URL. Have you tried saving `verify_anim.gif` to your hard drive, to ensure that the problem is the animated GIF itself, and not the fact it's stored on a remote server? – Andrzej Doyle Jul 06 '12 at 08:38
  • Yes i did as a local file but the same result. – itro Jul 06 '12 at 09:29
  • This [example](http://stackoverflow.com/a/5444422/230513) works on 1.5. – trashgod Jul 06 '12 at 09:47

1 Answers1

0

This works for me, but I'm using version 1.7.0_05.

EventQueue.invokeLater(new Runnable(){
  public void run(){
    JLabel label = new JLabel();

    label.setHorizontalAlignment(SwingConstants.CENTER);

    try{
      // URL imageURL = new URL("http://static.ak.fbcdn.net/rsrc.php/v2/yb/r/GsNJNwuI-UM.gif");
      URL imageURL = new URL("http://i34.photobucket.com/albums/d129/nirendaran/Speed/verify_anim.gif");

      label.setIcon(new ImageIcon(imageURL));
    }
    catch (MalformedURLException ex){
      ex.printStackTrace();
    }

    JFrame frame = new JFrame();
    frame.add(label, BorderLayout.CENTER);
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    frame.setMinimumSize(new Dimension(160, 120));
    frame.setVisible(true);
  }
});
dgolive
  • 425
  • 3
  • 8