package model.shapes; import javax.swing.*; /** * Square shape * This shape requires one parameter, the length of the sides, for the regular constructor. * It can be instantiated using a parameterless constructor, but then only makeFactory() may be used to obtain * a factory that can create a fully initialized Ellipse object. * * @author Mathias Ricken */ public class Square extends Rectangle { /** * Parameterless constructor. * Should just be used to call makeFactory() on the object. */ public Square() { } /** * Regular constructor. * When this constructor is used, the object is fully initialized. * @param s length of sides */ public Square(int s) { super(s,s); } /** * Make the factory that can create this kind of IShape. * @return make to create this IShape */ public AShapeFactory makeFactory() { // anonymously create factory that can be used as settings panel return new AShapeFactory(getClass().getName()) { /// text field for the side private JTextField _sidesField; // initializer block { setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); add(new JLabel("Sides: ")); add(_sidesField = new JTextField("100")); } /** * Create the IShape that matches the current parameters. * @return IShape */ public IShape makeShape() { return new Square(Integer.parseInt(_sidesField.getText())); }; }; } }