【发布时间】:2012-07-06 08:31:51
【问题描述】:
我正在使用 java 1.5 并希望在启动我的应用程序之前显示一个动画并在我的应用程序加载时关闭它。我在谷歌搜索后创建了一些东西,但如果我使用未显示的动画 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();
}
}
});
}
}
【问题讨论】:
-
在那个例子中,你的两个例子之间有一个更大的区别,因为动画是一个远程 URL。您是否尝试过将
verify_anim.gif保存到您的硬盘,以确保问题出在动画 GIF 本身,而不是它存储在远程服务器上? -
是的,我作为本地文件做了,但结果相同。
-
此example 适用于 1.5。
标签: java swing splash-screen animated-gif