(3)编写"ColoredCircle”类,表示圆周颜色的Color类对象borderColor和圆心颜色对象centerColor 至少定义如下几个ColoredCircle构造方法: ColoredCirle():将半径赋为0,将圆心赋为(0,0)点,将两个颜色赋为Color(0,0,0)对象 ColoredCirle(Point center,int radius):半径为radius,圆心为center,颜色为(0,0,0) ColoredCirle(Color centerColor,Color borderColor):半径为0,圆心为(0,0)点,颜色分别为centerColor和borderColor ColoredCirle(Point center, int radius, Color centerColor, Color borderColor):圆心为center,半径为radius,圆心颜色为centerColor,边框颜色为borderColor 设置颜色方法: void setCenterColor(Color c) void setBorderColor(Color c) 获取颜色方法: Color getCenterColor() Color getBorderColor()
时间: 2024-01-11 22:02:53 浏览: 67
以下是实现要求的代码:
```
public class ColoredCircle {
private Point center;
private int radius;
private Color centerColor;
private Color borderColor;
public ColoredCircle() {
this.center = new Point(0, 0);
this.radius = 0;
this.centerColor = new Color(0, 0, 0);
this.borderColor = new Color(0, 0, 0);
}
public ColoredCircle(Point center, int radius) {
this.center = center;
this.radius = radius;
this.centerColor = new Color(0, 0, 0);
this.borderColor = new Color(0, 0, 0);
}
public ColoredCircle(Color centerColor, Color borderColor) {
this.center = new Point(0, 0);
this.radius = 0;
this.centerColor = centerColor;
this.borderColor = borderColor;
}
public ColoredCircle(Point center, int radius, Color centerColor, Color borderColor) {
this.center = center;
this.radius = radius;
this.centerColor = centerColor;
this.borderColor = borderColor;
}
public void setCenterColor(Color c) {
this.centerColor = c;
}
public void setBorderColor(Color c) {
this.borderColor = c;
}
public Color getCenterColor() {
return this.centerColor;
}
public Color getBorderColor() {
return this.borderColor;
}
}
```
这个ColoredCircle类表示带颜色的圆,包含圆心坐标、半径、圆心颜色和边框颜色。我们定义了四个构造方法,分别对应不同的初始化方式。设置颜色的方法非常简单,只需要设置对应的颜色对象即可。获取颜色的方法也很简单,只需要返回对应的颜色对象即可。
阅读全文