JButton[] button = new JButton[noOfDays];
for(int j=0 ;j<studentNameList.size() ;j++) {
for(int i=0 ;i<button.length ;i++) {
button[i]=new JButton((i+1)+"");
attendencepanels.add(button[i]);
button[i].addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
----> button[i].setBackground(Color.red); //Local variable refenced from inner class must be final or effective final
//JOptionPane.showMessageDialog(null, "test");
}
});
我怎樣才能解決這個按鈕的問題[I] actionPerformed方法錯誤:從內部類中引用的局部變量必須是最後的或有效的最終
使按鈕陣列最終 – Jens
'最終的JButton []鍵=新的JButton [noOfDays];' –
要麼使其全球類或最終通過@jens –