• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What have you got so far?
 
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
simbra, check PM's
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic