标题有点令人困惑,但我想在颜色方法中添加一个整数。我的意思是,如果我有三种颜色,并希望通过for循环(如下所示)来完成它们:
Color color1 = something;
Color color2 = something;
Color color3 = something;
for (int i = 1; i < 4; i++) {
int r = color(i).getRed();
int g = color(i).getGreen();
int b = color(i).getBlue();
}
答案 0 :(得分:0)
您可以将三种颜色存储在数组中,并在循环中访问该数组。
// take these three colors for example
Color[] colors = {Color.BLACK, Color.WHITE, Color.YELLOW};
for (int i=0; i<3; i++) {
int r = colors[i].getRed();
int g = colors[i].getGreen();
int b = colors[i].getBlue();
}