![](https://www.opentextbooks.org.hk/sites/opentextbooks/files/book_profile/cc_icon/by-sa.png)
JFrame is not responsible for arranging the GUI components that it contains. Instead it delegates such a task to its layout manager, LayoutManager. There are many concrete layout managers: FlowLayout, BorderLayout, GridLayout, etc. that arrange the internal components diferently. There are said to be diferent strategies for layout. The interaction between JFrame and its layout manager is said to follow the Strategy Pattern.
The strategy pattern is powerful and important design pattern. It is based on that principle of delegation that we have been applying to model many of the problems so far. It is a mean to delineate the invariant behavior of the context (e.g. JFrame) and the variant behaviors of a union of algorithms to perform certain common abstract task (e.g. LayoutManager). We shall see more applications of the strategy design pattern in future lessons.
At this point the only the buttons in the Frame1 example do not perform any task besides "blinking" when they are clicked upon. The example in the next lecture will show how to associate an action to the click event.
Click here to download code samples.
- 1261 reads