I'm trying to implement MVC in my program, this is currently my Controller class:
public class Controller {
private DatabaseModel model;
private View view;
public Controller(View view, DatabaseModel model){
this.model = model;
this.view = view;
this.view.getMainPanel().getCandidateForm().
addSubmitListener(new CandidateListener());
}
class CandidateListener implements ActionListener{
public void actionPerformed(ActionEvent e){
System.out.println("ACTION");
}
}
}
because my view includes several private sub JPanels - MainFrame and CandidateForm - with the latter being where the button is, at line 10 i pass the candidateForm panel back up to the controller and then call it's 'addSubmitListener()' method, which adds the custom listener to the button.
does this seem like the correct way to add the listener? should i be defining the CandidateListener this way in the Controller? or maybe make an anonymous class in the sub JPanel?
Any other advice on best practice for MVC and listeners would also be appreciated!