0

I need to load an image in my program, but I keep getting this error:

C:\Documents and Settings\Remy B\Desktop\programming\Java\Java Projects\NurseGUI\GraphPanel.java:30: cannot resolve symbol
symbol  : variable danger 
location: class GraphPanel
        danger = getImage(getDocumentBase(), "danger.jpg");

I'm assuming this is because you can only use getDocumentBase with applets? I googled, but I couldn't find a way to do the same thing if you aren't using an applet.

2
Contributors
3
Replies
4
Views
10 Years
Discussion Span
Last Post by masijade
0

Try using System.getProperty("user.dir") or System.getProperty("home.dir") if you want the current directory or if you want the directory where that class file also resides, then try getClass().getClassLoader().findResource("danger.jpg") Read the API for System and ClassLoader for a more detailed description.

0

Thank you.

However, I think I may have misdiagnosed my problem. Since I can't seem to use getImage or getAudioClip even when I specify the file path directly. When I went to sun's documentation about those commands, they come up under the "applet" class? What should I do to load images/sounds if I don't want to make the program an applet?

Thanks

0

For Audio check out the AudioInputStream class and its getAudioInputStream(File) and getClip() methods, and Clip's open(AudioInputStream) and play()/loop() methods.

For an Image see the read(File) method of ImageIO.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.