package controller; import model.ShapesModel; import model.shapes.AShapeFactory; import view.AFrame; import view.IPaintAdapter; import view.ISettingsAdapter; import view.ShapesGUI; import javax.swing.*; import java.awt.*; /** * The controller that instantiates and connects the ShapesModel and the * ShapesGUI. * The controller also instantiates the adapters. * The adapters are implemented as anonymous inner classes. * * @author Mathias Ricken */ public class ShapesController extends JApplet { /** * The ShapesGUI. */ private ShapesGUI _view; /** * The ShapesModel. */ private ShapesModel _model; /** * Instantiates the model and the view and connects them together * using anonymous inner class defined adapters. */ public void init() { _view = new ShapesGUI(this, new ISettingsAdapter() { // initializer block { // make new model _model = new ShapesModel(); } public void changeShape(AShapeFactory factory) { _model.changeShape(factory); } public String[] getShapeClassNames() { return _model.getShapeClassNames(); } }, new IPaintAdapter() { public void paint(Graphics g) { _model.paint(g); } }); } /** * Java VM Entry point. * @param args command line arguments */ public static void main(String[] args) { new AFrame("Shapes Application") { protected void initialize() { ShapesController controller = new ShapesController(); controller.init(); getContentPane().add(controller, "Center"); setSize(500, 500); setVisible(true); } }; } }