I am trying to figure out how to get the hexadecimal value from a RGB.
This is a snippet of my code:
it says that the operater & is undefined for the argument type(s) Color, int
any insight?
thanks
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
I am trying to figure out how to get the hexadecimal value from a RGB.
This is a snippet of my code:
it says that the operater & is undefined for the argument type(s) Color, int
any insight?
thanks
Because you're using the bit operator on a Color object.
invoke Color.getRGB() first.
Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code
Can you show an example of what you want to do?how to get the hexadecimal value from a RGB.
Give a sample input and output
Literally I want the user to enter a color like red. Since red is a java recognized color I want the program to convert the string into a color and then find the hexadecimal of that color so I can put it into a Jradiobutton to change the background of a gui with it.
so...
screen pops up and user enters "red"
then screen closes and a new screen pops up with a Jradiobutton with the hexadecimal of the entered color
and when pressed, the screen turns to that color, in this case "red"
To get from a String value of the name of a color to a String of its RGB value in hex, why not use a hash table with the key the name of the color and the value either an Integer with its RGB value or a Color object from which you can get its RGB value. Use the toHexString method to get the hexString.
sounds like it might work. how would I implement it?
You'd write code to load the hashtable.
Then use the hashtable methods to get the color value using the String the user entered.