【发布时间】:2020-01-31 04:24:49
【问题描述】:
我需要创建一个不带参数的方法来使颜色变暗,它位于这段代码的底部。它将整数的值调暗 20%。我不知道如何访问在这些 Color 类中创建的整数。 我用占位符“a”“b”和“c”代替应该访问确定颜色颜色的三个数字的位置。
public class Color {
final static Color RED = new Color(255, 0 , 0);
final static Color BLACK = new Color(0, 0 , 0);
final static Color GREEN = new Color(0, 255 , 0);
final static Color YELLOW = new Color(255, 255 , 0);
final static Color BLUE = new Color(0, 0 , 255);
final static Color MAGENTA = new Color(202, 31 , 123);
final static Color CYAN = new Color(0, 183 , 235);
final static Color WHITE = new Color(255, 255 , 255);
private int red;
private int green;
private int blue;
public Color(int a, int b, int c) {
if (a < 0) {
a = 0;
}
if (b < 0) {
b = 0;
}
if (c < 0) {
c = 0;
}
if (a > 255) {
a = 255;
}
if (b > 255) {
b = 255;
}
if (c > 255) {
c = 255;
}
Color custom = new Color(a, b, c);
}
public Color dim() {
int newA = a * 0.80;
int newB = b * 0.80;
int newC = c * 0.80;
Color newColor = (newA, newB, newC);
return newColor;
}
应该是 this.Color(0) 什么的
另外,我该如何解决这个检查两种颜色是否相同的布尔方法,'a'必须被替换。
public boolean equals(Color) {
if (Color a = Color b){
return true;
}
else {
return false
}
}
【问题讨论】:
-
你不认为这将是递归的
Color custom = new Color(a, b, c); -
你能更好地解释你的问题吗? IE。您在哪条线路上遇到问题?
-
您永远不会将红色、绿色、蓝色值分配给它们的属性(即
this.red = a) -
我知道为什么那会是递归的
-
@SkiMaskTheSlumpGod
Color调用Color,后者调用Color...好吧,你明白了