【发布时间】:2015-05-22 09:49:04
【问题描述】:
所以我在 stackoverflow 遇到了一种将 gif 图像添加到 jFrame 的解决方案,现在看起来程序接受了我在 stackoverflow 找到的代码。但是,定义图像位置可能有问题,所以我得到了我当前正在使用的代码以及下面的错误,请帮助!
public static void main(String args[])throws MalformedURLException {
URL url = new URL("f:/SDPproject/CheapDealsMobiApp/build/classes/cheapdealsmobiapp/Gif-1");
Icon icon = new ImageIcon(url);
JLabel label = new JLabel(icon);
JFrame f = new JFrame("Animation");
f.getContentPane().add(label);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
请注意,错误是“线程“主”java.net.MalformedURLException:未知协议:f”中的异常,这可能是导致不安的位置定义吗?如果是这样,解决方案是什么?
【问题讨论】: