我正在使用Netbeans IDE 7和JDK 7,没有框架。第一个窗口是JFrame,所有其他窗口都是JDialog,modal=true。
问题:
How do I correctly implement the MVC pattern with swing? From the ideas bellow Which one is better: (A) or (B)? Or maybe another one... Why is it better?
(A) Main:
MyModel model MyView view(model)
MyView:
MyController(this, model)
(B)
Main:MyModel model MyView View MyController controller(view, model)
when I click jbutton1 in MainFrame I need it to open the SettingsFrame for editing settings. where should I instantiate the View, the Model and the Controller of the SettingsFrame? In MainFrame Controller?
In terms of MVC organization and implementation, how should I handle more specific features that (apparently) lacks one or two of the MVC "legs" (either Model or View or Controller)? Should I create empty classes for them?
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
How to correctly keep and use an object with settings through the whole application? I will need it's information in different places (Views, Models, Controllers) but it might be altered by user during the runtime). Is it a good idea to make this model a singleton?
What should I do when:
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...
Any hints on how to know if I implemented MVC correctly? Should I process massive data in Model or Controller?
I'm also using a DAO, what I'm doing is: my model has a
ArrayList MyModel load()
method which creates an instance of the DAO and returns the ArrayList of Models returned by the DAO, and then sometimes I process this ArrayList of Models in the Model and sometimes I allow the Controller to process it. Is this a good practice or is there a better way? By Process I mean: iterate through the ArrayList and get the data from the models.
I Have a PasswordCheck jDialog to restrict access to some Views. How can I reuse it in terms of MVC, so that I can use the same PasswordCheck dialog for allowing/restricting access to different Views without doing a mess in the code?
Any other tips, hints, ideas, suggestions?
非常感谢您的时间和帮助。