aspose file tools*
The moose likes Applets and the fly likes Can i get the index of which button was clicked? 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 » Applets
Bookmark "Can i get the index of which button was clicked?" Watch "Can i get the index of which button was clicked?" New topic
Author

Can i get the index of which button was clicked?

Nitesh Panchal
Ranch Hand

Joined: Dec 23, 2008
Posts: 48
Hello,

Say suppose i created a Button array now when i click upon it the control goes to actionPerformed(ActionEvent e) method. Now i know that you get the source as well the string related to the button via getSource() and getActionCommand() respectively. But can i get the index of the button like which button was clicked? Thanks in advance!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
You'll need to iterate through the array and compare the event source to the button references you've stored in it.

Or you can make the index part of the command string, and extract it using string operations.


Ping & DNS - my free Android networking tools app
Nitesh Panchal
Ranch Hand

Joined: Dec 23, 2008
Posts: 48
Thanks Ulf!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Can i get the index of which button was clicked?