使用 Eclipse 导入图片
所以,我最近从 BlueJ 切换到 Eclipse(它好多了!),在移动一些 java 文件时,我意识到 Eclipse 不支持图片...在 BlueJ 中,要导入图片文件,您只需执行以下操作:
Picture picVariable = new Picture("PictureFile.bmp");
但是,由于某种原因,我在 Eclipse 中执行此操作时遇到语法错误...我如何在 Eclipse 中加载图片?
另外,要在 BlueJ 中显示图片,您只需执行以下操作:
picVariable.show();
...您将如何在 Eclipse 中执行此操作? 谢谢!
So, I recently switched from BlueJ to Eclipse (Its soooo much better!), and while moving over some of my java files, I realized that Eclipse doesnt support Pictures... In BlueJ, to import a picture file, you would just do:
Picture picVariable = new Picture("PictureFile.bmp");
But, for some reason I get syntax errors doing that in Eclipse... How would I load up a picture in Eclipse?
Also, to show a Picture in BlueJ, you would just do:
picVariable.show();
...How would you do that in Eclipse?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我对 BlueJ 不熟悉,但您不需要进行任何导入的事实告诉我“图片”是 BlueJ 的一些特定类。
当 Eclipse 说它无法解析类型时,这意味着它无法在类路径上找到类“Picture”的定义。
在普通的 Java 中,显示图片非常容易。
请参阅以下邮件列表主题以获得非常简单的方法:
http://www.java-forums.org/new-java/527-simplest-way-read-display-jpeg-image.html
基本前提是你创建一个ImageIcon,然后使用一个JLabel 来渲染它(假设您使用的是 SwingGui。
I'm not familiar with BlueJ but the fact that you don't need to do any imports tells me that 'Picture' is some BlueJ specific class.
When Eclipse says its can't resolve the type that means it can't find a definition for the class 'Picture' on your class path.
In normal Java its pretty easy to display a picture.
See the following mailing list thread for a very simple way:
http://www.java-forums.org/new-java/527-simplest-way-read-display-jpeg-image.html
The basic premise is you create an ImageIcon, then use a JLabel to render it (assuming you are using a SwingGui.
我找到了显然是你需要的图书馆。
http://introcs.cs.princeton.edu/java/stdlib/stdlib.jar
下载该 jar 文件,将其放在 Eclipse 项目目录中的项目文件夹中。右键单击 jar 并选择“添加到构建路径”
I found what is apparently the library you need.
http://introcs.cs.princeton.edu/java/stdlib/stdlib.jar
Download that jar file, drop it on your project folder in the Eclipse project directory. Right click on the jar and select 'Add to Build Path'