The way I always found it useful (for navigation purposes) is to create an anonymous inner class, which then delegates to the outer class:
listenedObject.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { listenedObject_actionPerformed(evt); } }); private void listenedObject_actionPerformed(ActionEvent evt) {
Then it is much easier to get the processing code in the IDE using the structural search (CTRL + F12 in IDEA, CTRL + O in Eclipse).
The problem of using one class (for example, the MyCoolPanel GUI) as a common listener for a group of its components (buttons, etc.) is that the actionPerformed method has many ugly if-else comparisons with figuring out which button is pressed is not very OO at all!
Of course, you should not worry too much about the performance aspects of these kinds of things - they are likely to be negligible as a last resort! Premature optimization is a bad thing.
source share