• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

repaint method and graphics

 
Mark Lockery
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Draw the background before the object, then repaint?
 
Craig Wood
Ranch Hand
Pie
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm moving this to the Swing/AWT forum, where it's more on-topic.
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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());
floatingComponent.setLocation(location)
}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic