I am assuming you already know what the dot notation means when used with an object reference and are just confused about using it with method call. If not do as nuzzle has suggested and read a basic tutorial.
Basically what you have shown a just a shorthand way of writing code. Rather than assign the reference returned from getClass() to a local variable and then using that local variable to call the object getResource(..) method you can write in as you have shown. In fact you can chain as many method calls as you like provide each method call returns an appropriate object reference for the following call. Back to your example, the following code snippets are essentially the same:
Code:Icon img1 = new ImageIcon(getClass().getResource("YES.png"));The second example you have shown is also a form of shorthand similar to the example above - I'll leave you to work that one out.Code:Class c = getClass(); URL url = c.getResource("YES.png"); Icon img1 = new ImageIcon(url);




Reply With Quote