Question 0-5

Give and describe an example of how the Composite pattern shows up in the AWT or Swing user interface libraries of Java.

Solution

Swing has a JComponent class for representing items that lie within windows, such as buttons and text fields. One subclass of JComponent is JPanel, so it can lie within a window, and a JPanel is itself a container of JComponents. Thus JPanel is an example of the Composite design pattern.

Back to Exam 0