previous | start | next

Inheritance from JFrame

We can revise the classes from the Rectangle example to use a specialized frame class:

Previous classes:
  • JComponent

    • RectangleComponent

  • RectangleComponentViewer

    The RectangleComponent is a final local variable in main.

    The main method creates the frame, the RectangleComponent, the controller for it, adds the component to the frame and makes the frame visible.

The revised classes:
  • JComponent

    • RectangleComponent
  • JFrame

    • RectangleComponentFrame

      The RectangleComponent is a private member of this class.

      The constructor creates this component and a controller for it, then adds the component to the frame.

  • RectangleComponentViewer

    The main method creates the RectangleComponentFrame and makes it visible.

The model, RectangleComponent, is not changed in the revised version.

Most of the responsibilities that were in the main method of the old RectangleComponentViewer have been assumed by the new RectangleComponentFrame.



previous | start | next