I have something like the code below:
for(int i=0;i<10;i++){
button=new JButton(buttons[i]);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
setPage(i);
}
});
menu.add(button);
}
However, the variable i
isn't defined in the scope of the ActionListener class. How can I pass the variable?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…