To do the actual layout, you add the layoutContainer
method.
That method first obtains the dimensions of the container using the
instance variables of the Dimension
instance returned by
getSize
. Then, that method positions and sizes all the known
components using setBounds
expressions:
import java.awt.*; public class MovieApplicationLayout implements LayoutManager { private Component meter; private Component list; private Component form; private Component poster; // addLayoutComponent and removeLayoutComponent definitions as in Segment 970 public void layoutContainer(Container parent) { Dimension d = parent.getSize(); int height = d.height; int width = d.width; if(meter != null) { meter.setBounds(0, 0, (int) (width / 3), (int) (height * 2 / 3)); } if(list != null) { list.setBounds((int) (2 * width / 3), 0, (int) (width / 3), height); } if(form != null) { form.setBounds(0, (int) (height * 2 / 3), (int) (2 * width / 3), (int)(height / 3)); } if(poster != null) { poster.setBounds((int) (width / 3), 0, (int) (width / 3), (int) (height * 2 / 3)); } } // Other definitions }