-1

我如何从这些代码中创建一个新的圆形类,其半径和中点(x,y)实现了界面画布?

public abstract class GraphicalObject { 
protected int x;
protected int y;
protected int color;

public abstract void setColor(bye r, byte g, byte b);
public abstract void setPosition(int x, int y);
}

public interface Canvas {
public void draw(GraphicalObject object); 
}
4

2 回答 2

2

尝试以下操作:

public class Circle extends GraphicalObject  implements Canvas {
  // implement all your method
}

编辑:从该抽象代码创建一个新类:

您不能实例化抽象类或接口 - 您可以实例化它们的子类/实现者之一。

您可以Anonymous Class为您的GraphicalObject班级创建,例如:

GraphicalObject object = new GraphicalObject() {
    public void setColor(bye r, byte g, byte b){
      // an implementation of an interface method
    }

    public void setPosition(int x, int y){
      // an implementation of an interface method
    }
 };
于 2013-11-06T12:00:04.417 回答
1
public class Circle extends GraphicalObject  implements Canvas 
于 2013-11-06T11:59:09.017 回答