To implement the LayoutManager
interface,
you provide variables that serve as handles for the named components.
Then, you can readily implement addLayoutComponent
and
removeLayoutComponent
.
import java.awt.*; public class MovieApplicationLayout implements LayoutManager { private Component meter; private Component list; private Component form; private Component poster; public void addLayoutComponent(String name, Component o) { if (name.equals("Meter")) {meter = o;} else if (name.equals("List")) {list = o;} else if (name.equals("Form")) {form = o;} else if (name.equals("Poster")) {poster = o;} else {System.err.println(name + " argument unrecognized");} } public void removeLayoutComponent(Component o) { if (meter == o) {meter = null;} else if (list == o) {list = null;} else if (form == o) {form = null;} else if (poster == o) {poster = null;} } // Other definitions }