如何使用Swing在Java中正确实现MVC?
如果您想了解更多详细信息,请让我知道,或参考此问题的最后几行。我已经读了很多书,我觉得我正在把一些简单的东西变成一些复杂的东西,我仍然被困在这里和那里,所以也许你可以在这些非常具体的点上帮助我 我使用的是Netbeans IDE 7和JDK 7,没有框架。第一个窗口是JFrame,所有其他窗口都是modal=true的JDialogs 问题:如何使用Swing在Java中正确实现MVC?,java,swing,model-view-controller,user-interface,jframe,Java,Swing,Model View Controller,User Interface,Jframe,如果您想了解更多详细信息,请让我知道,或参考此问题的最后几行。我已经读了很多书,我觉得我正在把一些简单的东西变成一些复杂的东西,我仍然被困在这里和那里,所以也许你可以在这些非常具体的点上帮助我 我使用的是Netbeans IDE 7和JDK 7,没有框架。第一个窗口是JFrame,所有其他窗口都是modal=true的JDialogs 问题: 如何使用swing正确实现MVC模式? 从下面的观点来看,哪一个更好:(A)还是(B)?或者另一个。。。为什么更好 (A) 主要内容: MyView: M
MyController(this, model)
(B) 主要内容:
a. The implementation of a TrayIcon
b. A URL connection class (an HttpsUrlConnection which will update data in the main jframe and also upload/download files)
c. A Directory Monitor (which will update data in the main jframe and also use the urlconnection to download a file)
d. My own implementation of TableModel
e. json
a. View needs some data from the Model?
What I'm doing: using the reference of Model which I keep in the View
b. View needs some data from the Controller?
What I'm doing: using the reference of Controller which I keep in the View
c. Model needs some data from the Controller?
Still didn't happen but I have no idea how to do correctly
d. Model needs some data from the View?
What I'm doing: pulling all my hair from my head...
e. Controller needs some data from the View?
What I'm doing: using the reference of the View which I keep in the Controller
f. Controller needs some data from the Model?
What I'm doing: using the reference of the Model which I keep in the Controller
g. One of FooModel, FooView or FooController needs data from one of BarModel, BarView or BarController?
What I'm doing: thinking of jumping from the highest building...
见我关于注册的说明;一个单身汉可能是合适的。+1,我喜欢这个想法,就像我喜欢这个链接一样,这也会帮助我的努力:-)+1对这个问题也很好地解释,我是第一个对这两个都投赞成票的人:-)谢谢你的回答。你说的“看我的注册说明”是什么意思?我以前看过suns的建议,但既然是你推荐的,我会更仔细地再读一遍,试着解决我的疑问。我也投了赞成票。+1也看到了这一点,它遵循了一个类似于所引用的图表。@dcr在我关于注册的说明中,我的意思是你可能想注册“每个组件(模型、视图、控制器)……一个顶级应用程序组件,以提供一个单一的参考点。”因此,只共享一个顶级应用程序对象;可以通过应用程序访问设置或其他常用数据。优点包括复制的引用更少,并且能够在运行时更轻松地交换实现;甚至可以使用Spring或其他IOC机制。@trashgood非常感谢您提供的示例。在搜索MVC时,我没有遇到这个示例。我会尽快仔细阅读+1.
a. The implementation of a TrayIcon
b. A URL connection class (an HttpsUrlConnection which will update data in the main jframe and also upload/download files)
c. A Directory Monitor (which will update data in the main jframe and also use the urlconnection to download a file)
d. My own implementation of TableModel
e. json
a. View needs some data from the Model?
What I'm doing: using the reference of Model which I keep in the View
b. View needs some data from the Controller?
What I'm doing: using the reference of Controller which I keep in the View
c. Model needs some data from the Controller?
Still didn't happen but I have no idea how to do correctly
d. Model needs some data from the View?
What I'm doing: pulling all my hair from my head...
e. Controller needs some data from the View?
What I'm doing: using the reference of the View which I keep in the Controller
f. Controller needs some data from the Model?
What I'm doing: using the reference of the Model which I keep in the Controller
g. One of FooModel, FooView or FooController needs data from one of BarModel, BarView or BarController?
What I'm doing: thinking of jumping from the highest building...