I am writing program with GUI using MVC design pattern. I have a question concerning using ActionListeners.
According to the MVC pattern, all of the ActionListeners should be included into Controller. Normally, as I believe they will be implemented into inner classes like.
However in case of many buttons etc. is it a good idea to move those inner classes to separate files in the same package? I know that they will not be inner classes any more, so is it a good design? And as I would need to use local variable from the Controller class can I simply set them a default access?
Controller class:
public class Controller{
GoogleMaps gMaps = null; // model
GUI gui = null; // view
public Controller(GoogleMaps gMaps, GUI gui) {
super();
this.gMaps = gMaps;
this.gui = gui;
this.gui.addButtonDownListener(new ButtonDownListener(this));
}
}
ButtonDownLister class:
class ButtonDownListener implements ActionListener{
private BudgetController buttonDownListener;
public ButtonDownListener(BudgetController buttonDownListener) {
super();
this.buttonDownListener = buttonDownListener;
}
@Override
public void actionPerformed(ActionEvent e) {
// some ActionEvent handler
}
}