requesting help with eclipse and using resources [message #202965] |
Tue, 10 May 2005 04:30  |
Eclipse User |
|
|
|
Originally posted by: plongo99.hotmail.com
i am working my way through the sun tutorial on swing and am having a
problem with one of the examples
( http://java.sun.com/docs/books/tutorial/uiswing/learn/exampl e5.html).
my problem is that the ptogram can not find the external image files used in
the dialog boxes.
the problem seems to be that i do not know how to tell eclipse where i have
put the image files.
the relevant bits of code seem to be:
// get the images and put them in an array of ImageIcons
for (int i = 0; i < NUM_IMAGES; i++){
images[i] = createImageIcon("images/image" + i + ".jpg");
}
and then latter ...
// returns an image icon or null if unable to locate resource
protected static ImageIcon createImageIcon(String path){
URL imageURL = LunarPhases.class.getResource(path);
//URL imageURL = LunarPhases.class.getResource("/images/image0.jpg");
if (imageURL == null) {
System.err.println("Resource not found: " + path);
return null;
} else {
return new ImageIcon(imageURL);
}
}
what i did ...
i created a new project in eclipse, then right-mouse buttoned the project
name in eclipse and created a new folder in the project. then i transfered
the image files to the newly created image folder, created the new class,
etc.,
when i run the program i get an error message saying the image files can not
be found.
any help would be greatly appreciated.
|
|
|
Re: requesting help with eclipse and using resources [message #203175 is a reply to message #202965] |
Wed, 11 May 2005 17:59  |
Eclipse User |
|
|
|
pat wrote:
> what i did ...
> i created a new project in eclipse, then right-mouse buttoned the project
> name in eclipse and created a new folder in the project. then i transfered
> the image files to the newly created image folder, created the new class,
> etc.,
Try creating a new source folder in addition to the one containing your
Java source, and create a new folder named "images" inside of it. Copy
your images to there, and run your program again.
--
Thorbjørn
|
|
|
Powered by
FUDForum. Page generated in 0.02784 seconds