Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

.jpg OR .gif as background of applet

 
Sam Cala
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can I use a .jpg / .gif image as backgrounf of the applet
How can I ?
Plz. let me know !!!
Regards and thanks in advance.
Regards,
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Either pass the image in as a parameter, or hard code a reference to the image into your applet. Then, in your paint() method, near the beginning do the following:

Then, do any other graphics operations after this to have graphics drawn on top of the image.
However, things aren't as easy as this... you may need to scale your image if the image is not the same size as your applet( Java can do this through a different drawImage() method where you specify the size you want the image to display as )... and if you want the image to be centered or tiled you will have to write that behavior yourself... ( by manipulating the x and y values of the drawImage() call )
HTH,
-Nate
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!