• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic