• Post Reply Bookmark Topic Watch Topic
  • New Topic

Useless arguments in AWT  RSS feed

 
Geoffrey Falk
Ranch Hand
Posts: 171
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on some graphics elements. These represent things that will be drawn onto a Canvas later. For example, one type of element may consist of an Image that was loaded from a file; Another may be a geometric shape, etc.

I would like my elements not to have a reference to any AWT components, because the elements may be created some other way (for example, generated by a mathematical formula or loaded from a database). There may be no AWT components around when the elements are created.

I am using MediaTracker to wait for an image to load. But for some reason I don't understand, MediaTracker wants a reference to an AWT component:



I do not want to have to provide any Component to the MediaTracker constructor. I do not see that it has any purpose. Can someone explain what is the point of this?? Creating a new Panel() for this is just a waste of memory.

I also want my elements to be able to paint themselves on a Graphics context:



Again, a similar question: Graphics.drawImage takes a reference to an ImageObserver. I put null here, and it still works.. so what is the point of this ImageObserver argument? Does it have any use, or is it just put there to confuse people?

Thanks
Geoffrey
[ August 09, 2005: Message edited by: Geoffrey Falk ]
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would guess drawImage() takes an ImageObserver because Sun wants to gently remind you that images are not necessarily static and you should take care to redraw images as they're loaded or if they're animated. If you're dealing with BufferedImages, passing null is harmless.

The MediaTracker seems to need the Component's Toolkit in order to prepare images for display. I guess they decided the safest way to get the toolkit was from the component that planned on displaying the images. I don't really understand the responsibilities of a Toolkit, but perhaps one of them is graphics acceleration.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!