This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

variable assignment problem

 
piero calca
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
piero calca
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Understood !
thanks again
 
Campbell Ritchie
Sheriff
Pie
Posts: 47274
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic