Add some buttons like this:
JButton bt;
for(int i = 0; i <= 10; i++){
bt = new JButton("BT : " + i);
bt.setPreferredSize(new Dimension(80, 80));
bt.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// fazer algo
}
});
jPanel.add(bt);
}
I need an action for each button, I'll give a very simple example. We assume that I have a vector of 10 positions, with numbers from 1 to 10. That is, I have a position in the vector for each button inserted. Clicking on the precise button displays the vector position number for the clicked button.
Button 1 - displays position 1 of the vector Button 2 - displays position 2 of the vector Boot 3 - displays position 3 of the vector .... and so on
How can I do this in the click event of the button?