I have a problem with obtaining ID / Variable Name of buttons. Generally I want create lights out game. I created panel of buttons (NxN, N from combo box) but I don't know how to get single button's ID after press. Any idea?
private void p1ActionPerformed(java.awt.event.ActionEvent evt) {
String temp = jComboBox1.getSelectedItem().toString();
ile=Integer.parseInt(temp);
jPanel1.removeAll();
jPanel1.setLayout(new GridLayout(ile,ile));
for (int i = 0; i < ile; i++) {
for (int j = 0; j < ile; j++) {
JButton btn = new JButton();
btn.setPreferredSize(new Dimension(40, 40));
btn.setBackground(Color.green);
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
/*What put here?*/
}
});
jPanel1.add(btn);
revalidate();
pack();
}
}
}