Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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
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
Rancher

Joined: Mar 22, 2005
Posts: 42958
    
  73
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.
Nitesh Panchal
Ranch Hand

Joined: Dec 23, 2008
Posts: 48
Thanks Ulf!
 
Have you checked out Aspose?
 
subject: Can i get the index of which button was clicked?
 
It's not a secret anymore!