Results 1 to 5 of 5
- 02-28-2013, 01:36 AM #1
Member
- Join Date
- Feb 2013
- Posts
- 2
- Rep Power
- 0
Need Help Trying to set an array for multiple RGB values
I'm trying to define a color by inputting multiple Red, Green, and Blue values from three arrays - although I can't seem to do so. I understand that this type of code may not be possible in the manner that i've written it... how can i accomplish this?
Here's the code:
I'm new to Java so any help would be much appreciate - thanks!Java Code:import java.awt.Color; public class colorSetter { public static Color acolor; public static void main(String[] args){ int[] redvaluesColor = {41,42,43,44,45,46,47,48,49,50}; int[] greenvaluesColor = {71,72,73,74,75,76,77,78,79,80}; int[] bluevaluesColor = {11,12,13,14,15,16,17,18,19,20}; acolor = new Color(redvaluesColor, greenvaluesColor, bluevaluesColor); } }Last edited by JavaClass; 02-28-2013 at 02:32 AM.
- 02-28-2013, 01:57 AM #2
Member
- Join Date
- Feb 2013
- Posts
- 3
- Rep Power
- 0
Re: Need Help Trying to set an array for multiple RGB values
every RGB code has 3 colors right?
-LearningTOprogramJava Code:int aColor[][] = { {1, 2, 3}, {4,5,6}, {7,8,9}, {10,11,12} }; //You can call this by: for (int i = 0; i < 2; i++){ for (int x = 0; x < 3; x++){ System.out.print(aColor[i][x] + "\t"); } System.out.println(); }
- 02-28-2013, 02:12 AM #3
Member
- Join Date
- Feb 2013
- Posts
- 2
- Rep Power
- 0
Re: Need Help Trying to set an array for multiple RGB values
Yes, and I'm trying to get it so that it has all of those combinations of integers for each R,G, and B. That code would require me to list every single combination out wouldn't it? Is there any way I could get it so it would check all of the different combinations as aforementioned?
Thanks!
- 02-28-2013, 02:46 AM #4
Senior Member
- Join Date
- Jan 2013
- Location
- United States
- Posts
- 682
- Rep Power
- 1
Re: Need Help Trying to set an array for multiple RGB values
I am not certain what you want to do but an RGB color can be created by calling java.awt.Color as follows:
Regards,Java Code:import java.awt.Color; ... Color aColor = new Color(20,20,20); ... //You could then store the color in a list of colors: ... List<Color> myColors = new ArrayList<Color>(); myColors.add(aColor);
JimThe Java™ Tutorial
YAT -- Yet Another Typo
- 03-01-2013, 01:32 AM #5
Senior Member
- Join Date
- Oct 2010
- Posts
- 316
- Rep Power
- 3
Re: Need Help Trying to set an array for multiple RGB values
Hi JavaClass, welcome to the forums.
The code written in #1 wouldn't work anyway as you are atttempting to construct a new color using arrays as the parameters.
See the link below for information on basic arrays.
Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)
Just to demonstrate a way to simplify your code:
The above code will generate a fixed array of ten colours, each containing the colours from your initial code.Java Code:import java.awt.Color; public class colorSetter { public static void main(String[] args) { Color[] colours = new color[10]; for(int i = 0; i < colours.length(); i++) colours[i] = new color(i+41, i+71, i+11); } }
I should point out this is not the only way of doing this. For example, as Jim has already shown, Lists can be used as an alternative to fixed size arrays.
Regards.Last edited by Ronin; 03-01-2013 at 01:36 AM. Reason: Code indentation
Similar Threads
-
Return multiple values from array lookup?
By tbhawk in forum New To JavaReplies: 2Last Post: 07-31-2011, 03:56 PM -
trying to create an array with multiple values per instance
By aconti in forum New To JavaReplies: 14Last Post: 06-29-2011, 03:49 PM -
Multiple values of different types in an object
By scheffetz in forum New To JavaReplies: 2Last Post: 03-23-2011, 08:34 PM -
need to input values from a text file into an array and count values
By pds8475 in forum New To JavaReplies: 14Last Post: 01-22-2011, 02:36 PM -
[SOLVED] Multiple return values
By Manfizy in forum New To JavaReplies: 17Last Post: 05-25-2009, 12:07 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks