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
?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With