java mvc使用_如何使用Swing在Java中正确实现MVC?

如果你想要更多的细节,请让我知道,或参考这个问题的最后一行.我已经读了很多,我觉得我把一些简单的东西变成一些复杂的东西,我仍然被困在这里,所以也许你可以帮助我在这些非常具体的点.

我使用Netbeans IDE 7和JDK 7,没有框架.第一个窗口是JFrame,所有其他窗口都是带有modal = true的JDialog.

问题:

>如何使用swing正确实现MVC模式?

从以下想法中哪一个更好:(A)或(B)?或者也许另一个…为什么更好?

(一个)

主要:

MyModel model

MyView view(model)

我的看法:

MyController(this, model)

(B)

主要:

MyModel model

MyView View

MyController controller(view, model)

>当我在MainFrame中单击jbutton1时,需要打开SettingsFrame来编辑设置.我应该在哪里实例化“设置”框架的“视图”,“模型”和“控制器”?在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

>如何通过整个应用程序正确保存和使用具有设置的对象?我将需要它的信息在不同的地方(视图,模型,控制器),但它可能会在运行时被用户改变).使这个模型成为一个单身吗?

>在以下情况下应该怎么办?

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...

>任何提示如何知道我是否正确实现MVC?我应该在模型或控制器中处理大量数据吗?

>我也在使用DAO,我在做什么是:我的模型有一个

ArrayList MyModel load()

该方法创建DAO的实例并返回由DAO返回的Model的ArrayList,然后有时我在Model中处理Models的ArrayList,有时我允许Controller处理它.这是一个很好的做法还是有更好的方法?按程序我的意思是:迭代ArrayList并从模型中获取数据.

>我有一个PasswordCheck jDialog来限制对某些视图的访问.我如何在MVC方面重用它,以便我可以使用相同的PasswordCheck对话框来允许/限制对不同视图的访问,而不会在代码中混乱?

>任何其他提示,提示,想法和建议?

语境:

我需要在短时间内开发一个Java Swing MVC软件,尽管默认情况下,我不是Java开发人员,而不是用来实现MVC模式,特别是在Java(我得到想法,但有时它缺乏我的知识实现类之间的关系).

应用程序基本上是一个本地/在线文件的监视器,主框架中的JTable显示此数据.我正在使用新的WatchService API来跟踪本地文件,并使用DAO将其信息保存在h2数据库中,并在主框架jtable中重新加载该数据.我还必须通知用户有关新文件(我正在使用TrayIcon).对于在线文件监控/上传/下载我使用HttpsUrlConnection和json.它也可以允许设置自定义.

提前感谢您的时间和帮助.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值