java - 如何更改图形颜色
问题描述
所以我试图改变这些矩形在画布上绘制时的颜色,但即使我为图形设置了颜色,它们也总是呈灰色。这是我的代码:
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);
}
}
解决方案
推荐阅读
- docker - 如何使用 docker 将 rasa 服务器暴露给 slack?
- javascript - 在 iOS 13 safari/chrome 浏览器中播放音频 (mp3) 的延迟
- python - 使用 django 查询从多个表中检索详细信息
- python - 在python3中的特定路径中导入包
- coroutine - 启动多个暂停乐趣
- css - 下拉内容不显示 W3.CSS
- android - 本机库没有从 golang 条件实现加载到 apex_defaults?
- objective-c - 在 Xcode 11.3 中读取文档中的文件失败
- java - Linux top 命令报告处于等待状态的 Java ThreadPoolExecutor 线程的 CPU 使用率高(将 Jetty 服务器从 9.0.6 更新到 9.4.22 之后)
- javascript - FETCH IE11:第二次提取在 ie 11 中不起作用