I have a JPopupMenu
with several JMenuItem
s inside. Each JMenuItem
has it's own ActionListener
, but the code looks rather messy having several anonymous inner classes in a row. I've seen some people organize several ActionListener
s like this:
public class Foo implements ActionListener {
private JMenuItem item1, item2;
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == item1) {
...
} else if (e.getSource() == item2) {
...
}
}
}
While this looks neater, I don't like the idea of having it visible. Are there any better ways of organizing several ActionListener
s?
Thanks