File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes adding images to JPanel ***************URGENT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "adding images to JPanel ***************URGENT" Watch "adding images to JPanel ***************URGENT" New topic
Author

adding images to JPanel ***************URGENT

simbra Liegh
Greenhorn

Joined: Feb 16, 2004
Posts: 2
hi, im making a game and want to add a GIF image to a JPanel as a background. however i am using the drawImage() method and i am basically stuck!!!could you please please help me
Thanks
Amy Phillips
Ranch Hand

Joined: Apr 02, 2003
Posts: 280
What have you got so far?
Ben Wood
Ranch Hand

Joined: Aug 14, 2001
Posts: 342
Hi. In my apps I have done this by defining a class which extends JPanel and then over-riding the paintComponent() method

where bi is a BufferedImage containing the image file you want to use, x and y describe the origin of the corner of the image, width and height are the dimensions of the image on the JPanel, and 'this' is used as an ImageObserver object.
Hope this helps!


SCJP 1.4, www.gsi3d.org.uk
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

OK, looks good so far...

What is the problem you are having? If the image isn't showing up, make sure that the path and name are correct... if not, you won't get an error, just an empty image.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
simbra Liegh
Greenhorn

Joined: Feb 16, 2004
Posts: 2
Originally posted by Amy Phillips:
What have you got so far?

at the moment i am stuck i cant add an image because i dont know how to.
i would greatly appreciate your help and a sample code if possible.Thanks
Ben Wood
Ranch Hand

Joined: Aug 14, 2001
Posts: 342
simbra, check PM's
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: adding images to JPanel ***************URGENT