• Post Reply Bookmark Topic Watch Topic
  • New Topic

Extending Image

 
Drew Lane
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just wondering if it's possible to extend java.awt.Image?
For example, I want to create some images in memory (they can be black squares for all I care).
I can do this with a method call, but is it possible to create a class that will do this?
I want to be able to say 'myImage img = new myImage();' and I will get back a black square returned to 'img'
Thanks,
Drew
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it is possible to extend image... but in your case, there are already classes for this. If you are using a newer version of Java look at the BufferedImage class. In older versions of Java you could use MemoryImageSource to create an Image from data.

I suppose you could extend just BufferedImage and have it just exclusively draw "the black square"...

Also, even easier to use than Images are the Icon and ImageIcon classes... if you need to put these images on components, look into using Icon or ImageIcon.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!