Re: Confusing Dot Operator
The dot notation and the new operator are very basic Java. Check them out in a textbook or tutorial.
Re: Confusing Dot Operator
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"));
Code:
Class c = getClass();
URL url = c.getResource("YES.png");
Icon img1 = new ImageIcon(url);
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.
Re: Confusing Dot Operator
Why I am here if I could do that? If you're not going to answer my questions don't answer at all, just go away.
Re: Confusing Dot Operator
Thank you. So instead of using the reference returned by the method; the method itself is called, I understand now, the other question about the new operator still hangs for me. Your response is appreciated double since you actually answered it and not told me to basically "Google it" as the post above.
Re: Confusing Dot Operator
Quote:
Originally Posted by
Fanatic2012
Your response is appreciated double since you actually answered it and not told me to basically "Google it" as the post above.
You're wellcome. I knew you would appreciate my advice to read a book.
Re: Confusing Dot Operator
Quote:
the other question about the new operator still hangs for me.
It's exactly the same thing, the setLayout(..) method calls requires you pass a reference to a LayoutManager. new FlowLayout() creates an instance of FlowLayout and returns a reference to the created object. Now work the rest out yourself - it's exactly the same as the other issue you had.