Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Color  RSS feed

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
I am passing color as String parameter,i can't able to get color object,but what i am getting is null.The Following method i am using
-----Color.getColor(green).-----
It is retuning null.How do you retrive the ColorObject,i have to pass color as String.What is solution.
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ,
i check this out
import java.awt.*;
class demo
{
public static void main(String[] args)
{
Color c=Color.getColor("green");

System.out.println(c.toString());
}
}
it returned null too.
i checked the api which states.
The argument is treated as the name of a system property to be obtained. The string value of this property is then interpreted as an integer which is then converted to a color.
If the specified property is not found, or could not be parsed as an integer, then null is returned
so my guess is that the system property for green has not been set and as such it returns the result.
Rahul
 
Aruna
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Each color is treated as an integer value in Color class. If u look at the Color class, all color names are final int variables only. So have an hashtable which has the color name and corresponding value. Once the color name is passed as string , take it as the key and get the corresponding value in the hashtable. With this value as argument, create a new Color object and use it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!