53 lines
853 B
Java
53 lines
853 B
Java
package shape;
|
|
import java.awt.*;
|
|
|
|
public class Shape {
|
|
protected Color color;
|
|
protected int x,y;
|
|
|
|
public void setColor(Color color) {
|
|
this.color = color;
|
|
}
|
|
public Color getColor() {
|
|
return color;
|
|
}
|
|
public double getArea(){
|
|
return x*y;
|
|
}
|
|
|
|
public void setX(int x){
|
|
this.x=x;
|
|
}
|
|
public int getX(){
|
|
return x;
|
|
}
|
|
|
|
public void setY(int y){
|
|
this.y=y;
|
|
}
|
|
public int getY(){
|
|
return y;
|
|
}
|
|
|
|
public double getPerimeter(){
|
|
return x*y;
|
|
}
|
|
|
|
public void move(int dx,int dy){
|
|
x += dx;
|
|
y += dy;
|
|
}
|
|
|
|
public void draw(Graphics g){
|
|
g.setColor(color);
|
|
g.fillRect(x,y,1,1);
|
|
}
|
|
|
|
Shape(){}
|
|
Shape(Color color,int x,int y){
|
|
this.color=color;
|
|
this.x=x;
|
|
this.y=y;
|
|
}
|
|
}
|