第七次实验课代码

添加C04~C07
This commit is contained in:
2025-10-29 00:52:52 +08:00
parent 1986bbbe3e
commit 1c869f816f
24 changed files with 761 additions and 3 deletions

View 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;
}
}