Getting Color object from String

hi
i need to get a Color object from a string provided at runtime.ie for the string "RED" i need to get a object of Color.RED.I have already tried to use decode() from Color class but it throws numberformat exception,can someone guide me.

Color.decode(String) will decode octal and hexidecimal representations of colors e.g.
Color poo = Color.decode("0x215DB8"); // hex description of color
works.
If you want to use RED, BLUE ... read them at run into a String or whatever and then test this String to get what color the user wanted e.g.
read from text file at run time that button colour should be ORANGE.
In your code, put
String colourStr; // read what colour the user specified into this var
Color their_color = null;
if(colour.equals("ORANGE"))
their_color = new Color(Color.orange);
else if(colour.equals("BLACK"))
// you can guess what goes here.. and so on.
It often nice to make them specify the hex value of the colour because there are more of these than the predefined colours (shock horror).
Anyway,
seeya, Edd.

Similar Messages

  • Getting an object from HttpSession...

    Hi all,
    I am stuck which is according to me is very obvious...please correct me if I am wrong.
    I have a java.util.ArrayList object in my HttpSession object.
    Now in my helper class to which the request is passed from the servlet I am extracting this ArrayList object in one ArrayList object and putting it into the HashMap. After this, I am again extracting this ArrayList object from the HttpSession and assigning it to a newly created ArrayList object in my helper class. Now I am passing this newly created ArrayList object to a method. This method after processing changes this ArrayList object. And finally I am putting this changed ArrayList object in the HashMap I created earlier.
    After doing all this, when I am trying to extract and print these ArrayList Objects from the session object...I found my first ArrayList object has also been affected by the same change as the second one. The expected result was only the second object will be changed. I am stuck with this.
    I know it has something to do with references....but I am not able to understand that when I am trying to create two new copies by extracting an object from the Session...and changing one how is my second object getting affected. Any help will be appriciated.
    The code for this is as follows:
    "phSessionState" is a collection object in HttpSession which holds all the other objects. We are not putting different objects directly in the HttpSession.
    "LineObject" is a simple JavaBean kind of class with gettrs and setters
    ArrayList originalList = (ArrayList)phSessionState.getData("lineObjectList");
    HashMap stagedLineObjects = new HashMap();
    stagedLineObjects.put("OriginalList", originalList);
    //Extracting same in another object and calling a method to update it.
    ArrayList tempList = (ArrayList)phSessionState.getData("lineObjectList");
    //Method to update the ArrayList
    updateLineObjectList(tempList, request);
    stagedLineObjects.put("UpdatedList", tempList);
    //Trying to get the objects from the HashMap and print
    System.out.println("Retriving OriginalList...");
    ArrayList List1 = (ArrayList)stagedLineObjects.get("OriginalList");
    for(int i=0; i<List1.size(); i++)
         LineObject lo = (LineObject)List1.get(i);
         System.out.println(lo.getUserID() + "\t" + lo.getPassword()
    + "\t" + lo.getFirstName() + "\t" + lo.getMiddleName() + "\t" +
    lo.getLastName());
    System.out.println("Retriving UpdatedList...");
    ArrayList List2 = (ArrayList)stagedLineObjects.get("UpdatedList");
    for(int i=0; i<List2.size(); i++)
         LineObject lo = (LineObject)List2.get(i);
         System.out.println(lo.getUserID() + "\t" + lo.getPassword()
    + "\t" + lo.getFirstName() + "\t" + lo.getMiddleName() + "\t" +
    lo.getLastName());
    Waiting for your valuable help...
    Thanks & Regards,
    Gauz

    You must remember that objects are passed by reference. So when you are passing around your ArrayList, you are actually passing a reference to the ArrayList. In other words, there exists one instance of your specific ArrayList in memory and what you are passing around are copies of the "reference" to that memory location.
    If you want to pass a copy of your ArrayList, you can create a copy of the ArrayList and pass the reference to that new copy. One way to do this is as follows:ArrayList originalList = new ArrayList();
    //Let's put two objects into the ArrayList
    originalList.add(1, new StringBuffer("object1"));
    originalList.add(2, new StringBuffer("object2"));
    //Now let's copy the ArrayList
    ArrayList copyOfList = new ArrayList(originalList);
    //now, you have two copies of the ArrayList.  You can make
    //changes to copyOfList without affecting originalList
    copyOfList.add(3, new StringBuffer("object3"));
    //Checking the size of each ArrayList will demonstrate a difference
    System.out.println("Original's size is " + originalList.size());
    System.out.println("Copy's size is " + copyOfList.size());
    //Output should be:
    //  Original's size is 2
    //  Copy's size is 3Please keep in mind that the objects within the ArrayList are also being passed by reference. So if you modify an object within originalList, those modifications will be reflected in the same object found in copyOfList.
    For example,StringBuffer sb = (StringBuffer)copyOfList.get(1);
    sb.append(":modified");
    //Now print the values of the first object in each ArrayList
    StringBuffer sbFromOriginal = (StringBuffer)originalList.get(1);
    StringBuffer sbFromCopy = (StringBuffer)copyOfList.get(1);
    System.out.println("Original's value is " + sbFromOriginal.toString());
    System.out.println("Copy's value is " + sbFromCopy.toString());
    //Your output should read
    //  Original's value is object1:modified
    //  Copy's value is object1:modifiedThis is because you made a copy of the ArrayList, but not a copy of each object within the ArrayList. So you actually have two seperate copies of ArrayList but they are referencing the same two objects in positions 1 and 2. The object in position 3 exists only in copyOfList.
    Hope this helps.

  • How to get stylesheet object from JAVA RESOURCE stored in DB

    Hi,
    I stored a xslt file in the database and have a JAVA RESOURCE file now. How can i get a stylesheet object from this resource file?
    I took the following class to get an impression how to get the contents of the resource but -although the name of the resource was spelled correctly- i got a file not found exception.
    Whats wrong?
    public class PrintRessource {
    public static void print (String p_ressource){
    try {
    Class c = PrintRessource.class;
    System.out.println(c.toString());
    InputStream file = c.getResourceAsStream(p_ressource);
    if (file == null)
    throw new FileNotFoundException("XSLT file not in DB");
    byte[] buffer = new byte[4096];
    int bytes_read;
    while ((bytes_read = file.read(buffer)) != -1)
    System.out.println(new String(buffer, 0 , buffer.length));
    catch (Exception exp) {
    System.out.println(exp);
    Thanks

    The code works as is. I just forgot to add the slash in front of the Resource file name.

  • How to get File  object from Document Object . ?

    In conventional Dom Parsing we pass file to DocumentBuilder to get Document Object .
      File file = new File("c:\\MyXMLFile.xml");
      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
      DocumentBuilder db = dbf.newDocumentBuilder();
      Document doc = db.parse(file); // gOT Document here . My problem is how do i get File object back from Document . If i have Document object with mi.
    Please consider above code as example i dont have File object in my code . i am using Xhive DB API where i get Document directly from API method .
    I need to convert this Document to File to get size of file
    Please suggest solution on this
    Edited by: AmitChalwade123456 on Dec 5, 2008 6:10 AM

    Hello Guys any views on this topic

  • How to get the object from an event

    Hey, thanks for helping.
    I'm trying to get the causing object from the event so i can run a method from the causing object,
    I tred using the getSource method inherited from the Event class but it doesn't see the method I have in that object (method1)
    I have this code:
    private class Over implements MouseListener
    public void mouseClicked(MouseEvent e)
    public void mousePressed(MouseEvent e)
    public void mouseReleased(MouseEvent e)
    public void mouseExited(MouseEvent e)
    public void mouseEntered(MouseEvent e)
    e.getSource().method1();
    }

    By the way, MouseEvent is a subtype of ComponentEvent, so it has the method:
    Component comp = evt.getComponent();which is convenient if "method1" is a Component method.
    Another btw: the "adapter" classes allow you to write listeners without cluttering your code with empty method bodies:
    class Over extends MouseAdapter  {
        public void mouseEntered(MouseEvent e) {
    }

  • Getting an Object Identifier String given a line of source code? HELP!

    (forgot to close the code tag on that last one!)
    Hi there,
    I am in desparate need of getting the object identifier given a particular line of source code. I need this for the debugger I'm writing, and since the jdb forum never gets reponses; just more unanswered questions.
    Right so, here's my problem in more detail. I can find out when a method is called in the Java virtual machine, and what its name is, and arguments and values and such like - using the Java Debugging Interface. BUT: unfortunately I cannot get the object identifier used in the source code that generated this call. I can however get a unique long id that identifies this object .. if that helps?(thinking hashtables here maybe?!)
    So, I may know that the constructor of EddClass has been called, and this the following line generated this call:
    EddClass edd = new EddClass();.. so what I need is a fail safe way of finding out "edd" from this - given all types of method calls.
    This is quite tricky because there are loads of ways methods can be called e.g.
    tty.getClassExclusions(); // Here I would know getClassExclusions had been called, and I would need to find out the object identifier "tty" called it
    Temp a, b, c;
    a = b = c = new Temp(); // Here I would know the constructor for Temp had been called, but now I would just want to know "c"
    AnotherEg ae = (new Egg()).getAnotherEg(); // and in this last case if I had found out that the Egg constructor had been called, I don't want to find out any object identifier from this line of code - since the object is anonymous; however if I had found out that getAnotherEg() had been called I would want "ae"Ok, well - please help: I'm making a Java Animator that will be freely available - that serves to graphically animate the execution of another java program. It'd be cool if one of you guys could help make it really cool. Plus there are Dukes available!!
    - Edd.

    this is quite a complicated question I think!
    I'm not sure but you maybe need to know just about the whole java lang. spec to do this.
    I'm sure there are plenty of free java parsers around, so unless you have a lot of time available its probably best to download one, figure some way to feed it a single line from within a code block, and extract its symbol table.
    Once you have the symbol table, there will probably be some other data available from the parser to say which are identifiers.
    Its then up to your debugger to figure out which one is the interesting one!
    sorry this is so vague but I think you've asked for something that is quite involved!
    asjf

  • How can I get some text from string like AB_CD_9.9.9_Sometext

    How Can I get
    only 9.9.9 from  string "AB_CD_9.9.9_Sometext" with powershell and regular expression?
    Thank you,
    Lei

    This works.
    if('AB_CD_9.9.9_Sometext' -match '\d\.\d\.\d'){$matches[0]}else{'notfound'}
    ¯\_(ツ)_/¯

  • Getting Sequence object from pre-step substep of Sequence Call based step type

    How to obtain reference to Sequence object from within pre-step substep of Sequence Call based custom step type?
    Given: new custom step type which based on NI Sequence Call step type. There is Pre-Step substep exist for this step type.
    How to get reference to Sequence object representing Sequence which will run?
    Although there is possible to examine SequenceAdapter and SequenceCallModule properties, it seems redundant since module (Sequence) is already loaded by TestStand ("NI TestStand Reference Manual. Table 3-4. Order of Actions that a Step Performs"   Action #6, while my code is running as Action #13).
    Thanks.
    Misha

    Could you explain what you want to do ?
    Why do you want to get the sequence object within a pre-step substep ?
    I give you some informations but I don't know if it's the better way to do what you want (because I don't know what you want to do with the sequence object).
    If the substep uses the ActiveX adapter :
    You can get the sequence object but you should save the object reference in a StationGlobals variable.
    And you should release the object reference within your sequence when you don't need it any more.
    If the substep uses another module adapter: 
    Get the step module, then the sequence name (module property).
    Then get the sequence object by the sequence name from the sequence file.
    Here are the paths to use for both methods :
    Sequence Name property path : Step.Module.SeqName
    Sequence Object path : RunState.SequenceFile.GetSequenceByName (seqname)

  • Getting NSData object from NSImage.

    I want NSData object from NSImage object.
    I looked in documentation and i didn't found any method to get back the data from image object. is it possible to retrieve NSData from NSImage ?
    Thanks....
    Message was edited by: xmax

    Somewhat ..
    - (NSData *)TIFFRepresentation
    Eric

  • How get SPWeb object from web exact url

    Hi,
    I have site collection object and its sub-web exact url. I want to get SPWeb object by using exact web url. I try SPSite.OpenWeb(string,bool) function by passing this excat url, but it throw an exception ie invalid character near ':'.
    SPSite.url = http://servername/site1
    subsite url is http://servername/site1/site2/site3. I need web object against subsite url.

    Hi,
    Thanks for the reply. Steven's answer help me.
    I also learned one more thing here. By providing your current web's exact url in SPSite constructor will create an instance of site of current web. But site.OpenWeb() will return the web object corresponding to provided url, not the web object of site url.
    using(SPSite site = new SPSite("http://servername/site1/site2/site3"))
          using(SPWeb web = site.OpenWeb())
    Here  site Url is http://servername/ and site.OpenWeb() return SPweb object against "http://servername/site1/site2/site3".

  • Can't get color value from DeviceN colorspace

    Hi.
    I use this code:
    if (colorSpec.value.colorObj2)
        colorValue = (PDEDeviceNColors)colorSpec.value.colorObj2;
        inVals[0] =  ( float )ASFixedTruncToInt32(PDEDeviceNColorsGetColorValue(colorValue, 0));
    When colorspace's stream is {0 0} everything is ok.
    But then I use colorspace with complex stream:
    { dup 1 mul 2 index 0 mul 2 copy lt { exch } if pop 3 index 0 mul 2 copy lt { exch } if pop 4 index 0 mul 2 copy lt { exch } if pop 5 1 roll dup 0 mul 2 index 1 mul 2 copy lt { exch } if pop 3 index 0 mul 2 copy lt { exch } if pop 4 index 0 mul 2 copy lt { exch } if pop 6 1 roll dup 0 mul 2 index 0 mul 2 copy lt { exch } if pop 3 index 1 mul 2 copy lt { exch } if pop 4 index 0 mul 2 copy lt { exch } if pop 7 1 roll dup 0 mul 2 index 0 mul 2 copy lt { exch } if pop 3 index 0 mul 2 copy lt { exch } if pop 4 index 1 mul 2 copy lt { exch } if pop 8 1 roll pop pop pop pop }
    In Acrobat 10.0 code still work good. But in Acrobat 11.0 I have Access Violation exception when i try to get color value.
    Please tell me in what could be the reason.

    It could be a bug, but you'd need to open an official tech support case with developer support.

  • Get line x from string

    I need to do the following type structure on a string in
    Flash where tSTNames is a string
    This is typical director Lingo i would use to do this.
    repeat with i = 1 to tStNames.line.count
    tName = tStNames.line
    --stuff
    end repeat
    I know this will need to be a for loop of some kind but I
    don't see any easy way to get a line count or to extract a line of
    text at a time from the string.
    I keep hearing how wonderful Flash is -- but here's a simple
    string parsing need and it sure doesn't look easy.
    Must be missing something.
    Thanks

    You might want to take a litle peek at the String object.
    var s = "line 1\nline 2\nline 3\nline 4"
    var lines:Array = s.split("\n");
    trace("There are " + lines.length + " lines in: \n" + s);
    trace("");
    for(var i=0; i<lines.length; i++){
    trace("line "+i+" is " + lines

  • How to get color group from illustrator into flash

    Hi,
    I have difficulties with the color management between Illustrator and Flash.
    I have the original vector files in Illustrator and would like to use the color groups, I have in Illustrator, also in Flash.
    One way doing it is using the Kuler.
    But I can not get the colors from Illustrator into Kuler.
    Can someone advice how to manage that process?
    Many thanks in advance!

    I'm fairly new to this having only recently started using these tools again after six years, but will try to help! Go to "Explore", find a theme you like and click the "Edit" selection when you mouse over it. From there you can edit it or save a copy of it as is as whatever name you wish. In Photoshop or Illustrator, they will now show up in Adobe Color Themes (Window > Extensions > Adobe Color Themes) under "All Themes" in the drop menu. In these apps (and others that are Adobe Color Theme aware), any themes that you favorite on the site will show up under "My Favorites".
    If you're using Fireworks, it's different as it still uses Kuler (Window > Extensions > Kuler).  Themes you save or favorite on the site don't automatically show up there, however you can search for themes by name, and if you select "Custom" from the theme group dropdown, you can enter up to four names that will show up in that dropdown menu and produce as many results as the window can hold for an individual term. For instance, I saved a theme as "Copy of Industrial Calm" which if I enter in the search box, the "group" is a group of one. However, if I just type "Industrial", the window fills with options, yet there are MANY more results on the Adobe Color site and you would have to be specific to get the right one in that window.
    Hope that helps.

  • How to get URL type from String.

    Hi,
    Is there any way to convert a String or String to int to URL type? For example, I getting value form a JTextArea. This value will be a int ( A combination of number only) so I am converting the String the int and then can it be converted into URL???
    Thanks

    merit wrote:
    I tried reading it but I dont understand the syntax. Can you please show me how to do this?
    public uRLReader(String uRL)throws MalformedURLException{
                   URL newURL = new URL(uRL);
    retrun (newURL);
              }will this code convert the String to URL type?
    Thank you.What don't you understand? If you don't know how to use the API docs to use a class, then you need to start from the very beginning of a Java tutorial.
    Also, you have what looks like a constructor, but it's returning a value. C'tors don't return values at all, and the value you're trying to return is a URL, which means you'd have to declare this as a method that returns URL.
    You seem to be struggling with basic, fundamental concepts. I recommend you get a better handle on those before trying to do anything with URLs.
    [http://java.sun.com/docs/books/tutorial/]

  • Getting Color Name from the its color UID

    Hello;
    How to get the color name if I have its color UID that am getting from the IColorListControlData::GetSelection()
    thanks

    See ISwatchUtils
    virtual PMString GetSwatchName (IDataBase *iDataBase, UID swatchUID)=0
    Given the UIDRef, return the swatch name.

Maybe you are looking for