第七次实验课代码
添加C04~C07
This commit is contained in:
52
C06 Polymorphism/src/shape/Shape.java
Normal file
52
C06 Polymorphism/src/shape/Shape.java
Normal file
@@ -0,0 +1,52 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user