• Advertisement
Sign in to follow this  

loading images in java

This topic is 4005 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

Hi, im working on a game and for the moment my main class is flooded with "image-loading-code"... how can i load the images in a seperate class (imageload.class) ??

Share this post


Link to post
Share on other sites
Advertisement
You would need to make a separate class like you've suggested. You could have a method such as getImage(imageName). It would be handy to store the images so they don't have to be loaded every time. You could use a hash map for this, using the image's path/name as a key. That way, when you request an image from the class it will look up the hash map and return the image. If the image hasn't been loaded then go ahead and load it.

Share this post


Link to post
Share on other sites
javax.imageio.ImageIO.read(File file) works like a charm, just be sure to do it before you actually need the image.

Share this post


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

  • Advertisement