Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between Icon and ImageIcon?

Icon bug = new ImageIcon( getClass().getResource( "bug1.png" ) );
ImageIcon bug = new ImageIcon( getClass().getResource( "bug1.png" ) );

What's the difference between these two? My book always uses the way in the first line to declare an ImageIcon but wouldn't it be better to declare it the second way because more specifically it is an ImageIcon?

like image 493
stumped Avatar asked Dec 30 '13 01:12

stumped


1 Answers

Icon is an Interface, whereas ImageIcon is an implementation of that interface.

The first is better because it means you can change your ImageIcon for another implementation of Icon later without needing to change the rest of your application.

like image 91
sasankad Avatar answered Sep 30 '22 17:09

sasankad