File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Game Development and the fly likes getting picture into netbeans Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Game Development
Bookmark "getting picture into netbeans" Watch "getting picture into netbeans" New topic
Author

getting picture into netbeans

Manik Jay
Greenhorn

Joined: Jul 25, 2006
Posts: 4
I was going to develop a small game with netbeans.I wanted to load a picture into my game.I placed the picture in the directory where the jar file was and gave the full url to that picture But when I run the game there is an exception because the image didn't load.I want to know where i should place the image


"hello world" that's my motto
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Show us the code you are using to load the image and the exception. Then we can help you. At this point, we would be guessing. And I left my crystal ball at home.


GenRocket - Experts at Building Test Data
Kayvon Farvardin
Greenhorn

Joined: Oct 21, 2006
Posts: 4
Luckily I brought my crystal ball with me.

Now I'm not even sure if this is right since I am noob... but I don't think you enter the full directory path for the photo at all. You just do blah.blahBlah(mypicture.jpg) or somthing similar. Not C:/Program Files/NetBeans/Projects/MyUberGame/mypicture.jpg

If thats correct, this will be the first time I helped answer somones Java question before. *crosses fingers*
[ October 21, 2006: Message edited by: Kavon Farvardin ]
Manik Jay
Greenhorn

Joined: Jul 25, 2006
Posts: 4
Originally posted by Kavon Farvardin:
[

you enter the full directory path for the photo at all. You just do blah.blahBlah(mypicture.jpg) or somthing similar. Not C:/Program Files/NetBeans/Projects/MyUberGame/mypicture.jpg

Kavon Thanks for the help
but I tried both ways.first I typed
the full path name like C:/My Documents/mypicture.jpg then when it didn't work I copied the picture to the "src" directory of my project folder and typed in the full path to that location then again tried with just the name of the picture....but in the end nothing worked

[ October 31, 2006: Message edited by: Manik Jay ]
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
do not access resources (pictures, config files ...) with full file p´┐Żath. Use a resource path instead. Put the resource on the class path (i.e. configure your IDE to have a directory "resources" on the class path) and the store all your pictures in this directory.

- resources/picture/a.jpg
- resources/picture/b.gif
- resources/config/myIniFile.bla

then get the URL/input stream for this resource trough the class loader:

then something like this should do the trick

(or getResource() or the methods found in java.lang.Class (depending on Java version)

like this you do not need to change your program if you deploy it on another machine and you also do not mandate a specific file path. Or if you consider deploying using webstart or ....


pascal
Paulo Pontes
Greenhorn

Joined: Dec 06, 2004
Posts: 20
Only complementing Pascal...


I couldn't use "/" and had to use "\\" for a correct behavior under windows. is it the same at other platforms?
Manik Jay
Greenhorn

Joined: Jul 25, 2006
Posts: 4
Thanks a lot guys but 1 last question.how do you configr netbeans to have a "resources" directory.
Paulo Pontes
Greenhorn

Joined: Dec 06, 2004
Posts: 20
the easyest way is creating the directory as a java package, just dont put any class, just resource files. This way the make and run script will put the files where it belongs
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: getting picture into netbeans
 
Similar Threads
how to get location of mouse click with respect to picture?
scrolling graphics
animation in applet
problem in page refresh, image not getting refreshed properly
MyProfile page: Picture input box with no upload button?