So I need to get the “i” out of this loop put into a variable outside of this loop (I want this to happen when a button is clicked) using an action-listener…
Any idea how to to this?
ArrayList<Kaart> Thand=uno.gethSpeler().getHand();
for(int i=0;i<Thand.size();i++){
btnArr[i].setIcon(Thand.get(i).getImg());
btnArr[i].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
iKaart=i;
}
});
}
I think you want this – just creating a
finalvariable within the loop, taking its value fromi, so that you can refer to it in your anonymous inner class: