如果您想了解更多詳情,請告訴我們,或者參考此問題的最後幾行。我已經讀過很多東西,我覺得我正在把一些簡單的東西變成一些複雜的東西,但我仍然會陷入困境,所以也許你可以幫助我解決這些問題。如何使用Swing在Java中正確實現MVC?
我正在使用Netbeans IDE 7和JDK 7,沒有框架。第一個Window是一個JFrame,所有其他窗口都是modal = true的JDialog。
問題:
如何正確地實現擺動MVC模式? 從下面的想法哪個更好:(A)或(B)?或者也許是另一個...爲什麼它更好?
(A) 主營:
MyModel model MyView view(model)
MyView的:
MyController(this, model)
(B)
主營:MyModel model MyView View MyController controller(view, model)
,當我在大型機點擊的jButton1我需要它打開SettingsFrame進行編輯設置。我應該在哪裏實例化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負載(),它創建了DAO和實例
方法返回由DAO返回的模型的ArrayList,然後有時我處理模型中的模型的ArrayList,有時我允許Controller處理它。這是一種好的做法還是有更好的方法?按過程我的意思是:遍歷ArrayList並從模型中獲取數據。
我有一個PasswordCheck jDialog來限制對某些視圖的訪問。我如何根據MVC重用它,以便我可以使用相同的PasswordCheck對話框來允許/限制對不同視圖的訪問,而不會混淆代碼?
任何其他提示,提示,想法和建議?
語境: 我需要開發一個Java在短時間內搖擺MVC軟件,但默認情況下,我不是一個Java開發人員並沒有那麼用於實現MVC模式,特別是在Java(我明白了,但有時它缺乏實現類之間關係的知識)。 這些應用程序基本上是一個監視器,用於顯示此數據的主框架中帶有JTable的本地/聯機文件。我正在使用新的WatchService API來跟蹤本地文件,並使用DAO將它們的信息保存在h2數據庫中,並將它們重新加載到主框架jtable中。我還必須通知用戶有關新文件(對於我使用的TrayIcon)。對於在線文件監控/上傳/下載,我使用HttpsUrlConnection和json。它也可能允許設置自定義。
在此先感謝您的時間和幫助。
+1,我喜歡這個主意,我喜歡這個鏈接,也會對我的努力有所幫助:-) +1對這個問題也是很好的解釋,我是第一個贊同這兩個觀點的人: - ) –
謝謝你的回答。「請參閱我的註冊說明」是什麼意思?我之前看到過太陽的建議,但是,既然你推薦了它,我會再仔細一點仔細閱讀,並試着解決我的疑惑。我也贊成它。 – dcr
+1另請參閱此[示例](http://stackoverflow.com/a/3072979/230513),它遵循類似於圖的[outline](http://stackoverflow.com/a/2687871/230513)引用。 – trashgod