• Advertisement
Sign in to follow this  

[java] Loading an image in java NOT APPLET

This topic is 3822 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i am loading images i prefer jpg, but will settle for almost anything, i'm trying to load many images in a java program (this is NOT and applet) and also how would i position it by X and Y position any help code or links are appreciated thanks in advance thoover if i cannot load images at least how would i use artist commands (only know how to do this in applets, and i tried almost same way but with no luck also in java im using JFrame as my windows with a JPane inside the frame...) anything else you need please ask.

Share this post


Link to post
Share on other sites
Advertisement
now my question is, how do i get the java program to know that the images are in the jar not the folder itself???

Share this post


Link to post
Share on other sites
I'm not positive about this, but I think you could use something like this.getClass().getResource(String name) which will return a URL that you can use in ImageIO.read(). I think that "name" should be a path relative to the base of your package. So, if you have a package "foo.bar.TheClassThatNeedsTheImage", and the image is "foo/resources/image.bmp", then "name" would be "resources/image.bmp".

If this doesn't work then tell me and I'll look a little closer at how it should be done.

Greggles

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement