Results 1 to 7 of 7
  1. #1
    anthropamorphic's Avatar
    anthropamorphic is offline Senior Member
    Join Date
    Jun 2011
    Posts
    136
    Rep Power
    0

    Default Convert String To Advanced Color

    Hello, I have a small problem with an application I am making. I am working on a program right now and in this program you can open up a JColorChooser to choose the color and it saves it out to a textfile. Then every time you launch the program it checks this textfile to try and set the color. My problem is I am not sure exactly how to convert it from a String to a color like this java.awt.Color[r=102,g=255,b=102]

    One of the methods that I tried was this:
    Java Code:
    Color back = Color.getColor(output);
    output = java.awt.Color[r=102,g=255,b=102]

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,562
    Rep Power
    25

    Default Re: Convert String To Advanced Color

    You need to parse the String and extract the r,g and b values, convert them to ints so you can use them in the Coolor class's constructor.

  3. #3
    anthropamorphic's Avatar
    anthropamorphic is offline Senior Member
    Join Date
    Jun 2011
    Posts
    136
    Rep Power
    0

    Default Re: Convert String To Advanced Color

    Quote Originally Posted by Norm View Post
    You need to parse the String and extract the r,g and b values, convert them to ints so you can use them in the Coolor class's constructor.
    What do you think the best approach for doing this would be?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,562
    Rep Power
    25

    Default Re: Convert String To Advanced Color

    What format is the String that contains the values?
    The String class has several methods for working your way through the contents of a String.
    Look at the API doc for the String class.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Convert String To Advanced Color

    Why try to save the Color to a text file? If it needs to be saved, the Color class implements the Serializable interface, and so why not use serialization instead?

  6. #6
    anthropamorphic's Avatar
    anthropamorphic is offline Senior Member
    Join Date
    Jun 2011
    Posts
    136
    Rep Power
    0

    Default Re: Convert String To Advanced Color

    Quote Originally Posted by Fubarable View Post
    Why try to save the Color to a text file? If it needs to be saved, the Color class implements the Serializable interface, and so why not use serialization instead?
    Could you link me to a tutorial on serialization

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

Similar Threads

  1. Hot to convert string to int ????
    By java_no1 in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 06-07-2011, 07:40 AM
  2. String color
    By biggerthanblue in forum Java 2D
    Replies: 1
    Last Post: 04-10-2011, 04:32 AM
  3. SetColor GOBJECT passing a string for color
    By Hollywood_99 in forum New To Java
    Replies: 0
    Last Post: 10-17-2010, 11:25 PM
  4. convert obj to string
    By isme in forum New To Java
    Replies: 11
    Last Post: 06-14-2010, 10:54 AM
  5. How to change string Color
    By Java.child in forum AWT / Swing
    Replies: 3
    Last Post: 01-06-2009, 04:27 AM

Tags for this Thread

Posting Permissions

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