Hello, I need to create n JButtons, the creation criteria is a table in the database that has n items. I have to create a button for each item and when I click the button it has to show me a message of the number of that item. Creating the button was easy, but I do not know how to create those methods.
int qtd=cartela.qtdCartelas();
JToggleButton btn[] = new JToggleButton[qtd];
for(int i=0;i<qtd;i++)
{
numeroBotao.next();
btn[i]=new JToggleButton(numeroBotao.getString(1));
panel.add(btn[i]);
System.out.println();
}
Ao clicar no botão necessito gerar um evento.
Conseguir fazer isso:
for(int i=0;i<qtd;i++)
{
//Cria os actionListener dos botões.
btn[i].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
//Necessito pegar o Texto do botão ou a posição dele no vetor
int l = Integer.parseInt(btn[i].getText());
//
}
});
}