【发布时间】:2014-09-06 19:25:43
【问题描述】:
我正在使用 java swing 来创建一个用户在其中绘制几个点的界面。我想要做的是在绘制这些点之后自动改变颜色的强度,从非常亮到暗,直到点消失。有谁知道有关如何更改颜色强度的任何教程,因为我找不到可以帮助我的东西。
编辑:感谢您的回答,他们帮助我更好地理解了如何使用 Color 类。我修复了它,所以我正在上传线程部分以帮助其他人是否需要做类似的事情......我正在处理黑色背景,所以我将颜色变暗而不是变亮。
public class MyThread extends Thread {
private Canvas canvas;
private int sleepingTime = 5000;
private Color color;
private int red, green, blue, alpha;
public MyThread(Canvas canvas) {
super();
this.canvas = canvas;
setDaemon(true);
}
public void run(){
while (true){
try {
System.out.println("going to sleep...");
Thread.sleep(sleepingTime);
} catch (InterruptedException e) {
System.out.println("sleep interrupted..");
return;
}
System.out.println("woke up!");
int size = canvas.points_list.size();
int i =0;
while (size > 0) {
color = canvas.points_list.get(i).getForeground();
red = (int) Math.round(Math.max(0, color.getRed() - 255 * 0.25f));
green = (int) Math.round(Math.max(0, color.getGreen() - 255 * 0.25f));
blue = (int) Math.round(Math.max(0, color.getBlue() - 255 * 0.25f));
alpha = color.getAlpha();
canvas.points_list.get(i).setForeground(new Color(red, green, blue, alpha));
size--;
i++;
}
canvas.repaint();
}
}
}
【问题讨论】:
标签: java swing colors brightness