package model.shapes; import javax.swing.*; /** * Circle shape. * This shape requires one parameter, the radius, 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 Circle object. * * @author Mathias Ricken */ public class Circle extends Ellipse { /** * Parameterless constructor. * Should just be used to call makeFactory() on the object. */ public Circle() { } /** * Regular constructor. * When this constructor is used, the object is fully initialized. * @param r readius */ public Circle(int r) { super(r,r); } /** * Make the factory that can create this kind of IShape. * @return factory to make this IShape */ public AShapeFactory makeFactory() { // anonymously create factory that can be used as settings panel return new AShapeFactory(getClass().getName()) { /// text field for the radius private JTextField _radiusField; // initializer block { setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); add(new JLabel("Radius: ")); add(_radiusField = new JTextField("100")); } /** * Make the IShape that matches the current parameters. * @return IShape */ public IShape makeShape() { return new Circle(Integer.parseInt(_radiusField.getText())); }; }; } }