• Advertisement
Sign in to follow this  

[java] re: loading an image (gif)

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

Hey, I am relatively new to java and am struggling with loading an image (usually use C++) The image is called 1.gif and is saved in the same directory as the java file I am working on. So I declared a (member) variable Image suitPic; Then in the constructor, I say suitPic = Toolkit.getDefaultToolkit().getImage("1.gif"); Finally in the paint() method, I wrote (where g is a Graphics device) g.drawImage(suitPic, x + 25, y+25, this); No image loads properly. Any suggestions ? I have been struggling with this for a couple hours now ! EDIT:::: Okay, now I can get it to work in the class card. However, I can not get it to work in the class deck, which uses card as a subclass. That is, I want to load the image to be saved in a card and then have cards that are stored in a deck. The problem before had to do with the directory that the images were saved in. It was in the same folder as the .java file but not the class file. However, this problem is still occuring with the deck class. Thanks [Edited by - GameDev135 on May 30, 2005 7:24:22 PM]

Share this post


Link to post
Share on other sites
Advertisement
Look Here. Also, is this an applet in a jar file. If you do not have the code in a jar file, you should just give the path of the picture. You don't need the Toolkit class.

Share this post


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

  • Advertisement