Your View code (your custom JPanel ) should have a Controller field (or some other way to get your controller class). Thus, when you receive an action from a user — for example, clicking a button — you can call controller.doTheAppropriateAction() . Either pass the Controller to the construct, or use the Javabean setter pattern on it, and install it immediately after building in your startup logic (which sounds like your "GUI class"). I prefer the Javabean template because GUI editors need parameterless constructors.
You must register your View as a Listener in the appropriate Controller (or Model ) classes, so that you will be automatically informed when something changes so that you can repaint() use Component (or do something more advanced). This will be related to setting up your own interface (for View to implement) and listener processing logic in the Controller (or Model ).
Lombok PG deduces a template from the last.
akf provides an alternative: register the Controller as an ActionListener in your View code. The advantage of this approach is that your View code View not bound to a specific Controller , but the disadvantage is that your Controller will be bound to your View code. I tend to reuse Controller code for various user interface implementations (e.g. Swing, GWT, JSP), so my Controller and Model never dependent on any specific View or atomic user actions.
source share