Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to create a color array?

 
Samuel Fitzpatrick
Greenhorn
Posts: 10
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question: I am trying to declare and assign values to a color array using sRGB values in one line.
I have found that
Color[] c1 = {Color.RED,Color.WHITE,Color.BLUE};
works.
But how do I get
Color[] c2 = {(255,0,0),(255,255,255),(0,0,255)};
to work?
Currently I have
Color[] c3 = new Color[3];
...
c3[0] = new Color(255,0,0);
c3[1] = new Color(255,255,255);
c3[2] = new Color(0,0,255);
but, would like this in one line. Thanks.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, there's

But that's as compact as it gets, I think.
 
Samuel Fitzpatrick
Greenhorn
Posts: 10
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks, that was exactly what I was looking for.
 
Robbie shi
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Color[] c2 = {new Color(255,0,0),new Color(255,255,255),new Color(0,0,255)};
you should use constructor
Color(int ,int,int)
----
Robbies
-----------------------------
1.java IDE tool : JawaBeginer
2.Java Jar tool : JavaJar
http://www.pivotonic.com
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isn't that what we're doing?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic