用户界面在特定路径向Java GUI添加图片
我需要在代码中添加3张图片。 目前,这3张照片不在SRC文件夹中,但在它之外——我在说 关于Eclipse项目
这是我的代码:
Image myImage = new Image(null, "treasure1.jpg");
while (iterator.hasNext())
{
String current = iterator.next(); // get an original room in the maze
Coordinate mazeDot = null;
if (this.m_rooms.containsKey(current)) // if the string key exists
{
mazeDot = this.m_rooms.get(current); // get the coordinate of that specific room as two Ints
e.gc.drawImage(myImage,mazeDot.getXCoordinate(),mazeDot.getYCoordinate());
}
}
但是我想把那张照片(treasure1.jpg
)放在我项目的src
文件夹中。
我试过以下代码:
Image myImage = new Image(null, "src/treasure1.jpg");
但它不起作用,但经过编译(在我将图片放入src
文件夹后)。
src是小写的
知道怎么了吗
问候, 罗恩
共 (0) 个答案