I\'ve implemented MVC pattern for Java SE with Swing using PropertyChageSupport
and PropertyChageListener
. The diagram for implemented MVC is as fo
Your diagram suggests a model–view–presenter (MVP) pattern, which is compatible with Swing application design. In this context, Action is a convenient way to encapsulate application functionality for export from you model. As concrete examples:
DefaultEditorKit
and StyledEditorKit
export useful Action
types that operate on the Document
model common to text components. As shown in this example, such actions update the Document
, which indirectly updates the corresponding view component.
The ControlPanel
in the example cited here exposes a number of Action
instances that operate directly on an implicit model of List<Node>
and List<Edge>
.
First a caveat: I'm not a professional or student but a hobbiest, but having said that, my own preference is with your second example,
btnOk.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
modelController.btnOkActionPerformed();
}
});
The control would have to call methods on the view to extract information, and any methods it would call would be part of an interface that the view implements. My goal in this is to keep the view as dumb as possible and do almost anything to loosen coupling as much as possible.