Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Java中映射Paint中的颜色数组?_Java_Swing_Colors_Paint - Fatal编程技术网

如何在Java中映射Paint中的颜色数组?

如何在Java中映射Paint中的颜色数组?,java,swing,colors,paint,Java,Swing,Colors,Paint,下面是代码。我在这行中出错了 Paint[] p=new Paint[]{cols}; 但是如果我使用 Paint[] p=new Paint[]{cols[1]}; 它没有给出一个错误 Color[] cols = new Color[n]; for (int i = 0; i < n; i++) { cols[i] = Color.getHSBColor((float) i / n, 1, 1); } Paint[] p

下面是代码。我在这行中出错了

Paint[] p=new Paint[]{cols};
但是如果我使用

Paint[] p=new Paint[]{cols[1]}; 
它没有给出一个错误

    Color[] cols = new Color[n];

    for (int i = 0; i < n; i++)
    {
        cols[i] = Color.getHSBColor((float) i / n, 1, 1);

    }
    Paint[] p=new Paint[]{cols};
    return cols;
Color[]cols=新颜色[n];
对于(int i=0;i
p
是一个
绘画
数组
cols
是另一个数组
p
不能包含
cols
,因为
p
中的对象必须是
Paint
,而不是数组

如果要将
cols
的内容放入
p
,可以执行以下操作:

Paint[] p = new Paint[cols.length]; // create a new array with the same length as `cols`
System.arraycopy(cols, 0, p, 0, cols.length); // copy the contents
这相当于遍历数组的长度并跨每个元素进行复制

但是如果你真的想要一个
Paint
数组,我不知道为什么你会有
cols
数组。你可以这样做:

Paint[] p = new Paint[n];

for (int i = 0; i < n; i++) {
    p[i] = Color.getHSBColor((float) i / n, 1, 1);
}
Paint[]p=新油漆[n];
对于(int i=0;i
p
是一个
绘画
数组
cols
是另一个数组
p
不能包含
cols
,因为
p
中的对象必须是
Paint
,而不是数组

如果要将
cols
的内容放入
p
,可以执行以下操作:

Paint[] p = new Paint[cols.length]; // create a new array with the same length as `cols`
System.arraycopy(cols, 0, p, 0, cols.length); // copy the contents
这相当于遍历数组的长度并跨每个元素进行复制

但是如果你真的想要一个
Paint
数组,我不知道为什么你会有
cols
数组。你可以这样做:

Paint[] p = new Paint[n];

for (int i = 0; i < n; i++) {
    p[i] = Color.getHSBColor((float) i / n, 1, 1);
}
Paint[]p=新油漆[n];
对于(int i=0;i