I've implemented MVC pattern for Java SE with Swing using PropertyChageSupport
and PropertyChageListener
. The diagram for implemented MVC is as follows.
In the implementation of View
, I do property change in Model
with the help of Controller
.
View
contains code like following for Ok button.
btnOk.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
modelController.setNumber(Integer.parseInt(numberField
.getText()));
modelController.setName(nameField.getText());
}
});
Complete code can be found in SwingMVC.
Now, My question is, Do I write above code for btnOk
in View
or Should I write it in a method in Controller
so that in View
, I'll be doing
btnOk.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
modelController.btnOkActionPerformed();
}
});
Of above two implementations, Which is the preferred way to implement MVC?