What is the controller in Java Swing?

前端 未结 7 802
不知归路
不知归路 2020-12-23 10:38

I would like to apply the MVC design to my Java application using Swing in a meaningful way. Therefore my question is, how the controllers would be structured in Java Swing?

7条回答
  •  感情败类
    2020-12-23 11:22

    I have two options in mind:

    1. Every Component Listener is an own class, as part of the controller package
    2. Every Component Listener is an anonymous class inside the view package which delegates its call to a class with controller methods. Is both possible?

    Yes both is possible but I will prefer to write Single class which implements all actionListioner and assign that same to all component in your app. This way you can track all actions in your app at single point. Also this way you can make your view distinguish from controller.

提交回复
热议问题