Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Painting over a image

 
Andy Woods
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Is it possible to paint over a background image? What I am trying to do is have a background image and only paint over a certain part (like a 5x5 pixel square) when an event happens. Also, the new painted over I would like to have a mouse over and display some information.
Or, should i create the main background graphic with spaces to place the painted section or a smaller 5x5 image?
Sorry for being cryptic of some sorts.. Just having a tough time following Java's Swing book for this..
Andy
woods_a@acadmn.mercer.edu
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's possible to paint over a background image... all you have to do is paint the background image first and then paint the new stuff later, so it will paint on top of the background. It sounds like the easiest thing for you to do is have an extended JPanel or JComponent that has a paintComponent() method that first paints the background, and then has some if/else statements to decide what overlays to paint. For the mouse-overs, all you have to do is add MouseMotionListeners to the component and check for the x,y location of the mouseevent to see if you need to do a mouse-over.

-Nate
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic