Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing Static Variable  RSS feed

 
siddharth sekhar
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello , I am starting Java Swing programming and am confused on a piece of code

"setLayout(new FlowLayout(FlowLayout.LEFT));"

in this code , are we creating a anonymous object of FlowLayout class and passing a static member "LEFT" of FlowLayout class to the constructor and passing all these to the setLayout method ?

I am new to this , so sorry if i have made a silly thing

Thank you
 
Peter Muster
Ranch Hand
Posts: 74
5
Eclipse IDE Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are constructing a FlowLayout with the parameter FlowLayout.LEFT and passing this object to setLayout. The instance is not exactly anonymous but you have no direct reference to it. That means that you probably don't need to invoke any methods on it in this context. The code would be the same in two lines, just that you had a local reference to the layout (which you could use to invoke methods on the instance for example).



Oracle provides documentation for the FlowLayout (and Swing in general) which you can find here.

The parameter FlowLayout.LEFT (int value) is expected by the constructor of FlowLayout, although there is also a constructor that does not expect any parameters. You'll find the difference explained in the link I included above.
 
siddharth sekhar
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christian Pflugradt wrote:You are constructing a FlowLayout . . . . You'll find the difference explained in the link I included above.


Thanks for the links
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!