V
VisionSet
I know the reasons why method variables must be final in order they can be
accessed by an annoymous inner class, but take a trivial menu set up:
JMenuItem menuItem;
for(int m=1;m<=5;m++) {
menuItem = new JMenuItem(Integer.toString(m));
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
holder.setInt(Integer.parseInt(((JMenuItem)e.getSource()).getText()));
holder.setInt(m); // would be nice!!
}
});
menu.add(menuItem);
}
Obviously the int parseing is a total hack, but what would you do?
And no I really don't feel the need to subclass JMenuItem and provide an int
attribute!
accessed by an annoymous inner class, but take a trivial menu set up:
JMenuItem menuItem;
for(int m=1;m<=5;m++) {
menuItem = new JMenuItem(Integer.toString(m));
menuItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
holder.setInt(Integer.parseInt(((JMenuItem)e.getSource()).getText()));
holder.setInt(m); // would be nice!!
}
});
menu.add(menuItem);
}
Obviously the int parseing is a total hack, but what would you do?
And no I really don't feel the need to subclass JMenuItem and provide an int
attribute!