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 repaint method and graphics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "repaint method and graphics" Watch "repaint method and graphics" New topic

repaint method and graphics

Mark Lockery

Joined: Jun 04, 2004
Posts: 19
I think this may be a stupid question, but i made an applet where an image moves around as you move the mouse, and when you click in the same area as another (stationary) image, the stationary image changes. I managed to get the moving image to stop refreshing so fast by, well im not sure. But anyway, when i put one image over another, it always displays the stationary image over the moving one. Is there a way to tell it which image to display over the other?
Darin Niard
Ranch Hand

Joined: Jun 08, 2004
Posts: 118
Draw the background before the object, then repaint?
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

I'm moving this to the Swing/AWT forum, where it's more on-topic.

[Jess in Action][AskingGoodQuestions]
David Weitzman
Ranch Hand

Joined: Jul 27, 2001
Posts: 1365
You may be able to exploit JLayeredPane for this. During initializaiton you'd do this:

panel.getRootPane().getLayeredPane().add(floatingComponent, JLayeredPane.PALETTE_LAYER);

And then to move stuff around, you'd do something similar to this:

onMouseMoved(MouseEvent e) {
// Move it to the mouse
Point location = SwingUtilities.convertPoint(e.getSource(), e.getPoint(), panel.getRootPane().getLayeredPane());
I agree. Here's the link:
subject: repaint method and graphics
It's not a secret anymore!