aspose file tools*
The moose likes Beginning Java and the fly likes variable assignment problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "variable assignment problem" Watch "variable assignment problem" New topic
Author

variable assignment problem

piero calca
Greenhorn

Joined: Jan 05, 2012
Posts: 3
In the book: Introduction to java programming ( good , tons of exercises) i found this code (referred to earlier version of Java SDK) :



This sounds OK , we have a type (Container) a name and an assignment : the method getContentPane() returns the needed object.
But in the book HF Java ( great in explaing though concepts ) i read :



and i'm wondering : were is landing the object , since there is no type and no name ?
Thanks a lot for any explanation
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4642
    
    5

It's called method chaining. In your sample code, you are interested in adding button to the JFrame's contentPane, which, being a Container, has a method for that.

Perhaps a pair of redundant parentheses will make it more clear to you:Which means, take the Container returned by frame.getContentPane() and invoke its add(...) method, passing button as a parameter.

edit And, for your future reference, please UseCodeTags <-- link


luck, db
There are no new questions, but there may be new answers.
piero calca
Greenhorn

Joined: Jan 05, 2012
Posts: 3
Understood !
thanks again
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39436
    
  28
By the way: you don’t need myFrame.getContentPane().add(myButton); unless you use an old version of Java eg JDK1.4.
You can write myFrame.add(myButton);
Read this to find out why.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: variable assignment problem