Results 1 to 2 of 2
  1. #1
    Psyclone is offline Member
    Join Date
    Jan 2010
    Posts
    81
    Rep Power
    0

    Default Question about Strings and Color type

    Is there a way to convert a string into a color?

    I can't get the code below to work because it is looking for Color type and I'm passing it String. I've tried... Color mainColor = (Color) "color"+x;, but, of course, that doesn't work either.

    Java Code:
    Color color1 = new Color(0, 0, 0), color2 = new Color(100, 100, 100)
    
    int x = 2;
    
    Color mainColor = "color"+x;

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    No but you can use an array:
    Java Code:
    Color [] colors = new Color[]{new Color(0, 0, 0), new Color(100, 100, 100)};
    int x = 1;
    Color mainColor = colors[x];
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

Similar Threads

  1. using instanceof to get Object type and parent type?
    By xcallmejudasx in forum New To Java
    Replies: 2
    Last Post: 11-06-2008, 06:24 PM
  2. Confused beginner with Rectangle type question
    By sigssoft in forum New To Java
    Replies: 2
    Last Post: 10-08-2008, 02:56 AM
  3. [SOLVED] Cast string type to int type
    By GilaMonster in forum New To Java
    Replies: 9
    Last Post: 09-17-2008, 10:43 AM
  4. Another Color TabbedPane Example
    By Java Tip in forum javax.swing
    Replies: 0
    Last Post: 06-26-2008, 07:37 PM
  5. A bit of color!
    By tim in forum Java 2D
    Replies: 8
    Last Post: 02-11-2008, 11:57 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •