for (final String playerName: players) { option = new JRadioButton(playerName, false); option.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent evt) { partner = playerName; } }); partnerSelectionPanel.add(option); group.add(option); }
Local variables passed to inner classes must be final. Initially, I thought that you cannot make playerName final in a for loop, but you can actually. If this were not the case, you would simply playerName in an additional final variable ( final String pn = playerName ) and use pn from actionPerformed .
source share