Java论坛网»Java技术»求助---加载图片时怎样设置路径?

求助---加载图片时怎样设置路径?

问?:
我的图片放在D:/begincode/Begin_SCG/src="http://localhost/365java/upload/picture/2007-7/17/0771716275446426.bmp" 下 我在代码中也是这样取得的
this.getContentPane().add(new MyPane(new ImageIcon("D:/begincode/Begin_SCG/src="http://localhost/365java/upload/picture/2007-7/17/0771716275446426.bmp"")), new XYConstraints(74, 227, 255, 48));
不知是GUI中不能加载.bmp文件 还是我的路径设置有问题 还请诸位大虾多多指教
答!: 1:
不能加载BMP,你可以加载JPG,PNG,GIF格式的图像
答!: 2:
最好能用getClass().getResource()这个方法来得到图片的URL地址,这样就好加载了
答!: 3:
public class GuiUtil {

/** Returns an ImageIcon, or null if the path was invalid. */
protected static ImageIcon createImageIcon(String path) {
System.out.println(path);
java.net.URL imgURL = GuiUtil.class.getClassLoader().getResource(path);
System.out.println(imgURL);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}
}

相关JAVA教程:
跨页面的事务问题
求助---加载图片时怎样设置路径?
请各位大侠指点一下,数据连接的问题!
JTree如何编辑节点,大家帮忙看看
各位高手!好,怎么在JButton中设置标题的布局啊!
想学XML,看什么书比较好?
求助:jbuilder2006运行struts程序出错
Weblogic 下 关于ejb的一个问题
求救!!`各位高手能不能提供些学习JAVA方面的好网站
流程设计器问题
关于XML中加入DTD验证的问题!
weblogic里部署完毕,在调用的时候出了错