[問題] final variable

看板java作者 (還沒想到)時間14年前 (2011/07/26 16:53), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
大家好~~ 就是我想寫一個能產生page button的method 因為觀念不太清楚 一直卡在一個問題上面 public static void display(int num){ JButton btn[]; btn = new JButton[num+1]; for(int i =1;i<=num ;i++){ btn[i] = new JButton(""+i); btnPanel.add(btn[i], BorderLayout.NORTH); String a = btn[i].getText(); btn[i].addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent e) { !!!!!這一行=========> System.out.println(a); }} ); } } 為什麼一定要叫我改成final的variable呢? 要怎麼解決阿 謝謝大家(_ _) -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 211.23.86.187 ※ 編輯: god800606 來自: 211.23.86.187 (07/26 16:59)
文章代碼(AID): #1EBe24Sl (java)
討論串 (同標題文章)
文章代碼(AID): #1EBe24Sl (java)