mackol Posted December 7, 2002 Share Posted December 7, 2002 i have a 2d array of JButtons. now i want to know the exact index where the button is pressed down. if i were to use getSource method it would still not give me the index location. any ideas :cry: Link to comment Share on other sites More sharing options...
0 Londoner Posted December 10, 2002 Share Posted December 10, 2002 public class ..... imlements ActionListener ... ArrayList array = new ArrayList(); . . . for ( int i = 0; i < 100; i++ ) { JButton jButton = new JButton("Hello"); jButton.addActionListener ( this ); button.add( jButton ); } . . . public void onActionPerformed( ActionEvent e ) { object src = e.getSource(); int index = this.array.indexOf( src ); if( index != -1 ) { } } Link to comment Share on other sites More sharing options...
0 Londoner Posted December 10, 2002 Share Posted December 10, 2002 Or if you dont want to use the ArrayList but instead want to use JButton [] then just search through the array for( int = 0; i < array.length; i++ ) { if( src == array) { index = i; break; } } Link to comment Share on other sites More sharing options...
Question
mackol
i have a 2d array of JButtons. now i want to know the exact index where the button is pressed down.
if i were to use getSource method it would still not give me the index location.
any ideas :cry:
Link to comment
Share on other sites
2 answers to this question
Recommended Posts