Java Swing ImageIcon,在哪里放置图像? [英] Java Swing ImageIcon, where to put images?
本文介绍了Java Swing ImageIcon,在哪里放置图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在关注Java摇摆游戏的本教程: http://zetcode.com/tutorials/javagamestutorial/movingsprites/
I'm following this tutorial for java swing games: http://zetcode.com/tutorials/javagamestutorial/movingsprites/
此时:
ImageIcon ii = new ImageIcon(this.getClass().getResource());
image = ii.getImage();
我只是不知道我必须写什么样的路径以及我应该在哪里保存图像(哪个目录).
I just don't know what kind of path I have to write and where should I save my images (which directory).
你能帮我吗?您能举个例子吗?
Would you help me please? Would you give an example?
推荐答案
在您的src文件夹中,创建一个名为"images"或"files"的文件夹,然后将图像放入其中.
In your src folder, create a folder called "images" or "files" then put the image in there.
然后使用此:
ImageIcon(this.getClass().getResource("/images/filename.png"));
如果这不起作用,请尝试以下操作:
If that doesn't work, try this:
ImageIcon(this.getClass().getResource("images/filename.png"));
这篇关于Java Swing ImageIcon,在哪里放置图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文