previous | start | next

Controllers and Components

Since individual controllers are usually added to components, the controller code must have access to a reference to the component it will control.

There are several possibilities. The example has this organization:

This approach can make the main method become quite bloated.

Instead of having the main method of the application create the frame AND create the components AND add listeners to the components, we can use inheritance to create a subclass of JFrame that handles these responsibilities.

Then the main application can just create an instance of this specialized frame and make it visible.



previous | start | next