This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Painting over a image" Watch "Painting over a image" New topic
Author

Painting over a image

Andy Woods
Greenhorn

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

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.

-Nate


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Painting over a image