This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Getting MEAN with Mongo, Express, Angular, and Node and have Simon Holmes on-line!
See this thread for details.
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: 42955
    
  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!
 
 
subject: Can i get the index of which button was clicked?