简体   繁体   English

Color [] col = {Color.RED,Color.BLUE}; 在Java中是什么意思?

[英]Color[] col= {Color.RED,Color.BLUE}; what does it means in java?

I'm reading java swing and i'm having problem in understanding it. 我正在阅读Java swing,但在理解它时遇到了问题。 Is Color a class ? Color是一class吗?

Color[] col= {Color.RED,Color.BLUE}; 

What does it means in java? 在Java中是什么意思?

Is Color a class? 颜色是一堂课吗?

Yes. 是。

Color is a class that has many static members for the different colors, as well as a constructor for a specific color (RGB values). Color是一个类,具有许多用于不同颜色的静态成员,以及用于特定颜色(RGB值)的构造函数。

What this means 这是什么意思

Color[] col= new Color[]{Color.RED,Color.BLUE};

is an array of Colors called col which has the values of red and blue. 是一个称为col的颜色数组,具有红色和蓝色的值。 Notice I've changed it from Color[] col= {Color.RED,Color.BLUE}; 注意,我已经从Color[] col= {Color.RED,Color.BLUE};更改了它Color[] col= {Color.RED,Color.BLUE}; to Color[] col = new Color[]{Color.RED,Color.BLUE}; Color[] col = new Color[]{Color.RED,Color.BLUE}; because you have to actually create the color array (hence the new keyword). 因为您必须实际创建颜色数组(因此使用new关键字)。

Color is a Class and that line of code is declaring AND initializing an array of colors with the name col and initializing it with the constants Color是一类 ,该行代码声明并初始化带有名称col的颜色数组,并使用常量对其进行初始化

Color.RED and Color.BLUE 颜色。红色和颜色。蓝色

Color is a class, that has several constants, for instance RED and BLUE. 颜色是一类,具有多个常量,例如RED和BLUE。 These two instances of the class Color are put into an array. Color类的这两个实例被放入一个数组中。 So you have something like a "list" with two colors. 因此,您有一种带有两种颜色的“列表”。

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

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