help please
i have 20 textfields & buttons.
private JTextField[] myTextFields;
private JButton[] editButtons;
........
myTextFields =new JTextField[getListSize()];//getListSize returns the size of 20
editButtons =new JButton[getListSize()];
for(int index=0; index < getListSize(); index++){
myTextFields[index] =new JTextField(30);
editButtons[index] =new JButton("edit");
}
i am displaying these textfields & buttons as pairs in each line. I have 20 filenames displayed in each textfield. Now when i click on particular textfields adjacent edit button, then it should open that respective file. Now i am confused on how to identify as to which textfields ajacent edit button is clicked.
please help me
[1153 byte] By [
ArpanaKa] at [2007-10-3 4:39:27]

One of those buttons fires an ActionEvent which is passed to your
actionPerformed method in your ActionListener. The ActionEvent can
tell you the 'source' where the event came from:JButton button= (JButton)event.getSource();
for (int i= 0; i < editButtons.length; i++)
if (editButtons[i] == button)
// button number i was pressed
kind regards,
Jos
JosAHa at 2007-7-14 22:43:22 >

alternative approach
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Testing
{
public Testing()
{
final JFrame f = new JFrame();
JPanel panel = new JPanel(new GridLayout(5,1));
for(int x = 0; x < 5; x++)
{
JPanel p = new JPanel(new GridLayout(1,2));
final JTextField tf = new JTextField(""+x,5);
JButton btn = new JButton("OK");
p.add(tf);
p.add(btn);
btn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
JOptionPane.showMessageDialog(f.getContentPane(),"Number in textfield = "+tf.getText());
}
});
panel.add(p);
}
f.getContentPane().add(panel);
f.pack();
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
public static void main(String[] args){new Testing();}
}