How do I parse hex integer Color codes passed as parameters to my servlet?

Bogdan Sheptunov

[ I am trying to pass Color values like 0xeeeeee or 0xEEEEEE as values to parameters from a get post (in the header). However I am unable to process the value into an integer value which is a requirement for the Color(int) constructor I will use to create the new color based on this passed value, I have tried

int colorvalue=Integer.parseInt(req.getParameterValue("ColorParameter"));

It is throwing an NumberFormatException which I am printing displaying the actual value of the parameter e.g

<output> NumberFormatException : 0xEEEEEE </output>

Could anyone kindly tell me how to process this value of the parameter into an integer value so I may pass it to the Color(int) constructor. Thanks. ]

The keyword for you is Integer.decode(). Here is some sample code:

String hexValue = "0x11";
Integer decodedInt = null;
int result = 0;
    decodedInt = Integer.decode(hexValue);
catch (NumberFormatException e)
    System.out.println("Cannot convert '" + hexValue + "': " + e.getMessage());
if (decodedInt != null)
    result = decodedInt.intValue();
System.out.println(result); // prints out 17