I have a program that allows the user to select a type of shape, a color, and draw a filled shape of that type by clicking and dragging. I now want to apply the decorator pattern to my program, but I'm having trouble due to the constructor of the class that I want to apply the decorator to.
I have the following class that I am trying to apply the decorator pattern to AbstractShape.java
public abstract class AbstractShape implements Shape{
protected Point start;
protected Point end;
protected String name;
protected Color color;
public AbstractShape(String name, Color c, Point pt1, Point pt2){
this.name = name;
color = c;
start = pt1;
end = pt2;
}
It has two subclasses for the different type of shapes that you can make, and uses this interface: Shape.java
import java.awt.Graphics;
import java.awt.Point;
public interface Shape {
/* Enumeration for the types of shapes */
public enum ShapeType{
Ellipse,
Rectangle
}
/* abstract methods */
public abstract void draw(Graphics g);
public abstract String getName();
public abstract Point getStart();
public abstract Point getEnd();
public abstract java.awt.Color getColor();
}
I was attempting to implement the decorator pattern by creating an abstract decorator like this: ShapeDecorator.java
public abstract class ShapeDecorator extends AbstractShape{
private AbstractShape wrappedShape;
public ShapeDecorator(AbstractShape w){
wrappedShape = w;
}
public abstract void draw(Graphics g);
}
When I try to do this I get the error Implicit super constructor AbstractShape() is undefined. Must explicitly invoke another constructor. How can I fix this so that I can pass a shape to the decorator class?
Aucun commentaire:
Enregistrer un commentaire