简体   繁体   中英

Lifecycle of controllers in Swing application

I am creating a Swing application and I have created subclasses of JPanels, JDialogs etc. and I have created an own controller for each.

Example:

UserRegistrationDialog has a UserRegistrationDialogController

I use an instance of this user registration controller in another controller which handles the whole JFrame. The user registration dialog controller shows the dialog when the user clicks a button in the JFrame.

My question is: Should I create a new controller object each time the user clicks the button? Or should I create the controller on startup of the main controller and then invoke a showDialog method etc. on it that displays the dialog? And should the JDialog view instance be created each time or be retained by the controller? So the question is related to the lifecycle/scope of subcontrollers and views.

我的建议是创建控制器的单个对象,以便在整个应用程序中都可以使用控制器的单个对象。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM