aspose file tools*
The moose likes Java in General and the fly likes class and imageicon Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "class and imageicon " Watch "class and imageicon " New topic
Author

class and imageicon

kahkean chor
Ranch Hand

Joined: Jan 26, 2013
Posts: 56
Class myClass = this.getClass();
URL url = myClass.getResource("image/us.gif");

may i know,what is the purpose of initiated myclass using this.getClass?

and can some 1 tell me what is the different between imageicon and image.......thanks in advanced.
please dont shot me,i already try to search this stuffs ,however i still hard to understand because i am poor in english
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

Hi Kahkean, Welcome to the ranch!

kahkean chor wrote:Class myClass = this.getClass();
URL url = myClass.getResource("image/us.gif");

may i know,what is the purpose of initiated myclass using this.getClass?

The getClass() method gets a reference to an Object's Class. You have an instance of the Class (this) and you need a reference to the Class (because the Class Object has the getResource() method used to generate a URL relative to its package), so you call this.getClass().

kahkean chor wrote:and can some 1 tell me what is the different between imageicon and image.......thanks in advanced.
please dont shot me,i already try to search this stuffs ,however i still hard to understand because i am poor in english

The differences are many. You can read about the two classes in their API:
java.awt.Image
javax.swing.ImageIcon

Differences begin with one is in the AWT package, the other is Swing, on is abstract, the other is not. One knows how to open images and draw them from a URL, the other requires subclasses which you use to provide pixel data...


Steve
 
wood burning stoves
 
subject: class and imageicon