Attempting to create array for Color Class - invalid integer inputs
I'm attempting to create an array of color values (certain values for red, certain values for green, and certain values for blue).
So far i've successfully created the array for those values per each r, g, and b inputs for setting the color, however, I am not able to then input those values into the actual creation of the color.
This is where I'm at so far
Code Java:
/**
* Write a description of class ColorSetter here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.awt.Color;
public class ColorSetter {
public int[] redvaluesColor = {45,46,47,48,49,150,};
public int[] greenvaluesColor = {11,12,13,14,15,16,17};
public int[] bluevaluesColor = {70,71,72,73,74,75,76};
public static Color acolor;
public void main(String[] args){
acolor = new Color(redvaluesColor, greenvaluesColor, bluevaluesColor);
}
}
please help asap!
Thank-you!
Below is the error I am getting:
no suitable constructor found for Color(int[],int[],[])
constructor java.awt.Color.Color(java.awt.color.ColorSpace,flo at[],float is not applicable;
(actual argument int[] cannot be converted to java.awt.color.ColorSpace by method invocation conversion);
I understand that the constructor is not applicable for this method, how can I write a code that will store multiple rgb values under one color name?
Need Help Trying to set an array for multiple RGB values
edit: oops double posted!
Re: Attempting to create array for Color Class - invalid integer inputs
Quote:
how can I write a code that will store multiple rgb values under one color name?
A way to have multiple values with the same name is to put the values into an array or collection.
Re: Attempting to create array for Color Class - invalid integer inputs
Quote:
Originally Posted by
Norm
A way to have multiple values with the same name is to put the values into an array or collection.
Can you maybe show me how that would be done in this case? I thought I put them into an array or collection successfully with the lines:
Code Java:
public int[] redvaluesColor = {45,46,47,48,49,150,};
public int[] greenvaluesColor = {11,12,13,14,15,16,17};
public int[] bluevaluesColor = {70,71,72,73,74,75,76};"
Re: Attempting to create array for Color Class - invalid integer inputs
If you want an array of colors with their rgb values taken from the arrays you show,
define an array of Color objects the same size as those rgb arrays,
write a loop to access each element in the array
define a new Color object by indexing into each of the arrays for the r,g,b values and store that object in the Color array.