Amigos tenho um frame com um arrays de JButtons na minha tela. Como saber qual botao que foi acionado " que chamou o metodo abaixo " ??
private void cmdBotao_actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "O Botao é ??? ");
}
este é código completo
public class Frm extends JFrame {
private JButton[] botoes=new JButton[40];
private int valor;
public static void main (String [] args){
new Frm().setVisible(true);
}
public Frm(){
try {
jbInit();
} catch (Exception e) {
}
}
private void jbInit() throws Exception{
this.setSize(new Dimension(550, 500));
this.getContentPane().setLayout(new GridBagLayout());
int x=0; int y=0;
for(int b=0;b<botoes.length;b++){
if(x>6){
x=0;
y++;
}
botoes[b]=new JButton("Bt." + b );
botoes[b].setPreferredSize(new Dimension(100,100));
this.getContentPane().add(botoes[b], new GridBagConstraints(x, y, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(2, 2, 2, 2), 0, 0));
botoes[b].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cmdBotao_actionPerformed(e);
}
});
x++;
}
}
private void cmdBotao_actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(null, "O Botao é ??? ");
}
}
Obrigado!!!