JAVA Swing MVC - Main Controller?

后端 未结 2 807
我在风中等你
我在风中等你 2020-12-11 19:44

I\'m having some troubles designing the architecture of an application I\'m trying to develop. I\'m working on JAVA, and I started working on this application because I want

2条回答
  •  鱼传尺愫
    2020-12-11 20:17

    As discussed here, Swing components use a separable model architecture with the model and view loosely coupled using the observer pattern. Not every GUI control has to be part of your application's controller. Using an ActionListener, such as Action, is particularly convenient for encapsulating application functionality.

    Addendum: I'd use CardLayout, illustrated here to switch panels. Note how the Action handlers can be used with buttons, menus, combos, toolbars, etc. Each card's content can have it's own implementation of the MVC pattern, separate from the others. Use a PropertyChangeEvent, seen here, for communication between components.

    In general, Swing components, e.g. buttons and tables, already listen to their respective models, leaving you to focus on your application's data model and its listening views. Conveniently, a Swing model, e.g. ComboBoxModel or TableModel`, can have more than one listener.

提交回复
热议问题