因此,我尝试更改在画布上绘制这些矩形时的颜色,但是即使我为图形设置了颜色,它们也总是呈灰色。这是我的代码:
public static void rectTransition(int[] array, int smallerNumberIndex) throws InterruptedException
{
for(int x = 0;x<10;x++)
{
if(smallerNumberIndex%2==0)
{
canvas.getGraphics().setColor(new Color(000000));
canvas.getGraphics().clearRect(((smallerNumberIndex*10)+9)-x, 600, 1, -array[smallerNumberIndex]*10);
canvas.getGraphics().clearRect(((smallerNumberIndex*10)-1)-x, 600, 1, -array[smallerNumberIndex]*10);
canvas.getGraphics().drawRect(((smallerNumberIndex*10)-1)-x, 600, 1, -array[smallerNumberIndex]*10);
}
else
{
canvas.getGraphics().setColor(new Color(20, 217, 72));
canvas.getGraphics().clearRect(((smallerNumberIndex*10)+9)-x, 600, 1, -array[smallerNumberIndex]*10);
canvas.getGraphics().clearRect(((smallerNumberIndex*10)-1)-x, 600, 1, -array[smallerNumberIndex]*10);
canvas.getGraphics().drawRect(((smallerNumberIndex*10)-1)-x, 600, 1, -array[smallerNumberIndex]*10);
}
Thread.sleep(200);
}
}