All the Swing components start with ‘J’. The hierarchy diagram is shown below. JComponent is the base class.
Design pattern: As you can see from the above diagram, containers collect components. Sometimes you want to add a container to another container. So, a container should be a component. For example container.getPreferredSize() invokes getPreferredSize() of all contained components.
Composite design pattern is used in GUI components to achieve this. A composite object is an object, which contains other objects. Composite design pattern manipulates composite objects just like you manipulate individual components.
No comments:
Post a Comment