dcr*_*dcr 15 java model-view-controller user-interface swing jframe
如果您想了解更多详情,请告诉我们,或参考此问题的最后几行.我已经阅读了很多内容,我觉得我正在把一些简单的东西变成复杂的东西而且我仍然被困在那里,所以也许你可以在那些非常具体的方面帮助我.
我使用的是Netbeans IDE 7和JDK 7,没有框架.第一个窗口是JFrame,所有其他窗口都是JDialogs,模态=真.
问题:
如何使用swing正确实现MVC模式?从下面的想法哪一个更好:(A)或(B)?或者可能是另一个......为什么它更好?
(A)主要:
MyModel model
MyView view(model)
Run Code Online (Sandbox Code Playgroud)
我的看法:
MyController(this, model)
Run Code Online (Sandbox Code Playgroud)
(B)
主要:
MyModel model
MyView View
MyController controller(view, model)
Run Code Online (Sandbox Code Playgroud)当我在MainFrame中单击jbutton1时,我需要它来打开SettingsFrame进行编辑设置.我应该在哪里实例化SettingsFrame的View,Model和Controller?在MainFrame控制器?
在MVC组织和实现方面,我应该如何处理(显然)缺少一个或两个MVC"支路"(模型或视图或控制器)的更多特定功能?我应该为他们创建空课吗?
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
Run Code Online (Sandbox Code Playgroud)如何在整个应用程序中正确保存和使用具有设置的对象?我将在不同的地方(视图,模型,控制器)需要它的信息,但在运行时可能会被用户更改.使这个模型成为单身人士是一个好主意吗?
我应该怎么做:
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...
Run Code Online (Sandbox Code Playgroud)关于如何正确实现MVC的任何提示?我应该在模型或控制器中处理海量数据吗?
我也在使用DAO,我正在做的是:我的模型有一个
ArrayList MyModel load()
创建DAO实例并返回由DAO返回的模型的ArrayList的方法,然后有时我在模型中处理这个模型的ArrayList,有时我允许Controller处理它.这是一个好习惯还是有更好的方法?按进程我的意思是:遍历ArrayList并从模型中获取数据.
我有一个PasswordCheck jDialog来限制对某些视图的访问.如何在MVC方面重用它,以便我可以使用相同的PasswordCheck对话框来允许/限制对不同视图的访问而不会在代码中造成混乱?
还有其他提示,提示,想法,建议吗?
上下文: 我需要在短时间内开发Java Swing MVC软件,虽然默认情况下我不是Java开发人员而不是那么习惯于实现MVC模式,特别是在Java中(我明白了,但有时它缺乏我知道实现类之间的关系).这些应用程序基本上是本地/在线文件的监视器,主框架中有一个JTable来显示这些数据.我正在使用新的WatchService API来跟踪本地文件并使用DAO将它们的信息保存在h2数据库中,并在主框架jtable中重新加载这些数据.我还必须通知用户有关新文件(我正在使用TrayIcon).对于在线文件监控/上传/下载,我正在使用HttpsUrlConnection和json.它还可能允许设置自定义.
在此先感谢您的时间和帮助.
看看Sun(甲骨文)的建议.
作为一种简化,您可以让每个组件(模型,视图,控制器)注册一个顶级应用程序组件,以提供单个参考点,而不是每个组件(您的A或B)之间的单独引用.我引用的文章提供了推拉设计的想法; 我推荐push作为一种更流行的现代方法.披露:我有使用Java和MVC的经验,但在Swing本身没有MVC.
我应该在哪里实例化SettingsFrame的View,Model和Controller?
当然,是的,或者在顶级应用程序组件中.
我应该如何处理(显然)缺少一个或两个MVC"腿"(模型或视图或控制器)的更多特定功能?
我会将仅GUI的片段实现为您自己的GUI库.纯粹的算法/服务作为服务库.
我应该在模型或控制器中处理海量数据吗?
数据处理算法很适合控制器甚至服务库; 除了可能的数据类型转换或验证之外,您的模型不应该进行太多处理.
如何在整个应用程序中正确保存和使用具有设置的对象?
请参阅我的注册说明; 单身可能是合适的.
| 归档时间: |
|
| 查看次数: |
11544 次 |
| 最近记录: |