File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Painting over a image Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Painting over a image" Watch "Painting over a image" New topic

Painting over a image

Andy Woods

Joined: Nov 29, 2001
Posts: 5
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..
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

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.


Write once, run anywhere, because there's nowhere to hide! - /. A.C.
I agree. Here's the link:
subject: Painting over a image
It's not a secret anymore!