Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Attempting to create array for Color Class - invalid integer inputs

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Red face 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
    /**
     * 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?


  2. #2
    Junior Member
    Join Date
    Feb 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need Help Trying to set an array for multiple RGB values

    edit: oops double posted!

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,422
    Thanks
    49
    Thanked 2,215 Times in 2,188 Posts

    Default Re: Attempting to create array for Color Class - invalid integer inputs

    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.
    If you don't understand my answer, don't ignore it, ask a question.

  4. #4
    Junior Member
    Join Date
    Feb 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Attempting to create array for Color Class - invalid integer inputs

    Quote Originally Posted by Norm View Post
    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:
           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};"

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,422
    Thanks
    49
    Thanked 2,215 Times in 2,188 Posts

    Default 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.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. differnce between String class and Integer class
    By Indrajeet in forum Java Theory & Questions
    Replies: 2
    Last Post: December 16th, 2012, 06:22 AM
  2. can I create an array in a parameterized class
    By mia_tech in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 7th, 2012, 07:13 PM
  3. Why does the Color class have two variables for each color?
    By Melawe in forum Java Theory & Questions
    Replies: 5
    Last Post: May 10th, 2012, 04:21 PM
  4. Finding the range of 2 integer inputs
    By dunnage888 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 1st, 2012, 02:54 PM
  5. In a class create an array list of elements of another class, help!
    By LadyBelka in forum Collections and Generics
    Replies: 3
    Last Post: May 4th, 2011, 05:00 PM