1

I make 2D game in AWT and I had all files in one package. Now I divided files into some packages. Images, which I called with:

ImageIcon ii=new ImageIcon(this.getClass().getResource(image));
img=ii.getImage();

now I call with:

ImageIcon ii=new ImageIcon("cz/ryska/awtgame/images/"+image);
img=ii.getImage();

This code is in class in package cz.ryska.awtgame.basic

But when I start game, displays game scene but not display images. Scene is empty. But any Java error is not induced. Images are probably found but not display. What is problem?

4

1 回答 1

1

..在我更改包结构之前,绘画是有效的。

您所做的不仅仅是更改包结构。变化是第一个是通过 加载图像URL,而第二个是从 a 加载图像File(其中String代表路径)。AnURL可以与嵌入式资源一起使用,而 aFile不能。

查看信息。页面embedded-resource了解更多信息。

于 2012-07-16T01:23:59.257 回答