简体   繁体   English

Java Swing中的MVC模式?

[英]MVC Pattern in Java Swing?

请举例说明Java SWING包中使用的MVC模式?

Basically, a Swing component is itself a controller, which has a reference to a view and a model. 基本上,Swing组件本身就是一个控制器,它具有对视图和模型的引用。

The view is in the JComponent.ui field that is inherited by all swing components and used by the Look&Feel mechanism to provide different visual representations of Swing components. 视图位于JComponent.ui字段中,该字段由所有swing组件继承,并由Look&Feel机制用于提供Swing组件的不同可视表示。

There are different setModel() methods in various subclasses that use different model types such as TableModel or ButtonModel , which can be implemented by an application programmer to contain the actual data that the Swing UI displays and manipulates. 各种子类中有不同的setModel()方法,它们使用不同的模型类型,如TableModelButtonModel ,它们可以由应用程序员实现,以包含Swing UI显示和操作的实际数据。

Look at javax.swing.JTable and javax.swing.table.TableModel. 查看javax.swing.JTable和javax.swing.table.TableModel。 JTable is the View, TableModel is the Model, and the code you write with listeners and events are the Controllers that say when the View needs to be updated. JTable是View,TableModel是Model,您使用侦听器和事件编写的代码是控制器,它们表示何时需要更新View。

我有很好的使用Martin Fowler的Presentation Model和Java Swing实现的经验。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM