Java SE MVC implementation with Swing

后端 未结 2 1897
情歌与酒
情歌与酒 2020-12-18 14:22

I\'ve implemented MVC pattern for Java SE with Swing using PropertyChageSupport and PropertyChageListener. The diagram for implemented MVC is as fo

相关标签:
2条回答
  • 2020-12-18 14:47

    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>.

    0 讨论(0)
  • 2020-12-18 15:10

    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.

    0 讨论(0)
提交回复
热议问题