很抱歉,我有一个ArrayList可以存储多个对象。每当我绘制这些对象时,我也会将颜色设置为绿色。我的问题是,alpha值完全被忽略了。为什么? (但不是实际的颜色,因此不会显示alpha值。)
我首先尝试使用setColor方法执行常规方法。但这没有用。我还写了一个方法,以确保我遍历所有对象。那也不起作用。
执行此操作的通常方法:(无效)
private void drawWatchers(Graphics2D g) {
for (int i = 0; i < watcher.size(); i++) {
g.setColor(new Color(46, 139, 87, 150));
g.fillRect(watcher.get(i).getX(), watcher.get(i).getY(), 30, 30);
}
}
我编写的代码可以确保我遍历所有对象 (也不起作用)
public Color setColor(int r, int g, int b, int a){
return new Color(r, g, b, a);
}
//On the other class:
for (int i = 0; i < watcher.size(); i++) {
g.setColor(watcher.get(i).setColor(46, 139, 87, 150));
g.fillRect(watcher.get(i).getX(), watcher.get(i).getY(), 30, 30);
}