Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating an ImageIcon  RSS feed

 
Ratheesh Narayanan
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear All,

I have a question, whenever we create an icon for any component, we used to write..

Icon img = new ImageIcon("pic.gif");

In this what I observed is Icon is an interface, but ImageIcon is a class.

Can anyone explain me how an interface can initialize with a class and why it is so?

Thanks and regards,
ratheesh
 
venkat chaitanya pagadala
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey here you are not instantiating a interface but just instantiating a class and storing it in a interface referrence variable.like you know any class's instance can be stored in the interface's referrence variable that the class implements the class ImageIcon implements Icon
 
Raghavan Chockalingam
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An implementation of the Icon interface that paints Icons from Images - SUN


Basically interfaces define how things should be. But different objects if they want to be like things defined in an interface then they should implement those interfaces....so what I was trying to say was, an image is different from an icon. Icon has a set of rules how it should be and ImageIcon implements this interface and thus converting an image into an icon. You create an instance of this ImageIcon class to convert your normal images to icons that can be used anywhere even in menubars.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!