简体   繁体   English

创建后更改java.awt.Color的RGB颜色

[英]java.awt.Color changing rgb color after creation

When I create a Color object with java.awt.Color, I can set its color with the constructor, but i don't figure out how to change it after (when my color object is already created). 当我使用java.awt.Color创建Color对象时,可以使用构造函数设置其颜色,但是我不知道之后如何更改它(当我的color对象已经创建时)。

So is it a way to set again RGB values after construction ? 那是一种在构造后再次设置RGB值的方法吗? I don't see any setters in the regular class ... 我在普通班上看不到任何二传手...

Color light_color = new Color(0,0,0);

As it seems to be impossible, I need to give a Color object to the setColor function of my Graphics object but i also need to be able to change RGB values. 似乎不可能,我需要为我的Graphics对象的setColor函数提供一个Color对象,但我还需要能够更改RGB值。 Is it a way to rewrite the class or something to add RGB setters ? 这是重写类的方法还是添加RGB setter的方法? i'm beginner in Java ^^. 我是Java ^^的初学者。

No, you can't change it. 不,您无法更改。 A Color object is designed to be immutable. Color对象被设计为不可变的。 That's why there are no setters. 这就是为什么没有二传手。

The same applies to the Java FX Color class. Java FX Color类也是如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM