File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can i get the index of which button was clicked?

 
Nitesh Panchal
Ranch Hand
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ulf!
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic