Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
simbra Liegh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What have you got so far?
 
Ben Wood
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
simbra Liegh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
simbra, check PM's
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic