I am currently replacing my anonymous ActionListeners
new ActionListener() {
@Override
public void actionPerformed(final ActionEvent event) {
First of all you should provide public methods for all actionPerformed used in your actions (createPerson, removePerson, etc.). All these action methods should be in one class (I call it PersonController). Than you need to define your AbstractPersonAction:
public class AbstractPersonAction extends AbstractAction {
private PersonController controller;
public AbstractPersonAction(PersonController aController) {
controller = aController;
}
protected PersonController getContrller() {
return controller;
}
}
Now you can extract all your actions into separate classes.
public class CreatePersonAction extends AbstractPersonAction {
public CreatePersonAction(PersonController aController) {
super(controller);
}
public void actionPerformed(ActionEvent ae) {
getController().createPerson();
}
}
These actions can be a part of an outer class or be placed in separate "actions" package.