繁体   English   中英

如何在Java中使用动画gif文件作为初始屏幕?

[英]How to use animated gif file as a splash screen in java?

我正在使用Java 1.5,希望在启动应用程序之前显示动画,并在加载应用程序时关闭它。 我在Google搜索后创建了一些东西,但是如果我使用的不是动画gif,则动画gif不会动画。

请问有人有什么问题,知道怎么做吗?

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();
            }
        }
    });
}
}

这对我有效,但是我正在使用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);
  }
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM