• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

class and imageicon

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic