简体   繁体   中英

Java Swing application - How can the controller access the UI?

I'm about to create a desktop application. I decided to do it in swing. Now I am confused about the architecture that I'm going to use. I decided to do something like.

ui-controller-service-dao

I'm confused mainly in the relationship between the controller and the UI. I understand that the controller does the operations that the ui needs to do like the controller handles the events of the ui, such as when a button is click. But for cases like when a button is clicked then disable some ui, it means the controller needs to acces the ui to do the disabling. Now how can provide access to ui from controller?

The Controller will have a link to its respective view and model. A button click would not have to go through the controller since its the responsibility of the UI itself to handle this event. On the other hand if you are opening an internal frame and there are multiple panels, then these should be displayed by going through the controller. And if say one panel wants to change the value of another panel, then it should go through the respective controller to which that view belongs to and not interact directly with the view.

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