Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

how to draw lines without change background's image?  RSS feed

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I draw an image in Jpanel as background,and following want to achieve lines or circles movement on the panel. however, when the line move using draw a white color line to overwrite, the background's image changed as well. how can I achieve move the lines without change the image?
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pursuing this answer a bit further:

Is there any good to be gained by taking advantage of the various layers that the Swing model makes available? I.e., draw the image as shown, but put the ball on the Transparent layer.

If you want to mouse click on the ball, does the answer remain the same?

Thanks
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any good to be gained by taking advantage of the various layers that the Swing model makes available? I.e., draw the image as shown, but put the ball on the Transparent layer.

I don't notice any advantage. It seems like one advantage of drawing on a transparent top layer would be to preserve the drawing while we swap or manipulate the image below.

If you want to mouse click on the ball, does the answer remain the same?

It seems to. Let's try it and see:
 
Norm Miller
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is very neat!

Thank you.
 
eric zheng
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot!
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!