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

String data = group.getSelection().getActionCommand();  RSS feed

 
siddharth sekhar
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone explain me what is happening in this piece of code

String data = group.getSelection().getActionCommand();

here group is a ButtonGroup object of radio button in java swing .

are we passing group.getSelection() to getActionCommand(); or we are calling two function at same time ? I am confused ,

Pl help
 
Campbell Ritchie
Marshal
Posts: 55711
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Apart from the fact that action commands are probably very bad design?

You have a group; those are used for radio buttons (Java™ Tutorials Section). You put several radio buttons in a group; when you click one button all the others become unselected. So you should be able to work out what group.getSelection() means.
Then buttons have a getActionCommand method which returns the text used for their action command. A smallButton might use "small" and the largeButton would then use "large" as action commands.
 
siddharth sekhar
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Apart from the fact that action commands are probably very bad design?

You have a group; those are used for radio buttons (Java™ Tutorials Section). You put several radio buttons in a group; when you click one button all the others become unselected. So you should be able to work out what group.getSelection() means.
Then buttons have a getActionCommand method which returns the text used for their action command. A smallButton might use "small" and the largeButton would then use "large" as action commands.


so we are passing two pieces of information . one from getSelection() and another from getActionCommand to string data ?
 
Knute Snortum
Sheriff
Posts: 4073
112
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so we are passing two pieces of information . one from getSelection() and another from getActionCommand to string data ?

No, we are calling two methods in sequence. First we call getSelection() from group and it returns a button. Then from that button object we call getActionCommand().
 
siddharth sekhar
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Knute Snortum wrote:
so we are passing two pieces of information . one from getSelection() and another from getActionCommand to string data ?

No, we are calling two methods in sequence. First we call getSelection() from group and it returns a button. Then from that button object we call getActionCommand().


Now i am getting it . now i am going to create the same logic with my own classes .. thank you
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!