Hi, I want to ask you following question: I have one HTML file in which I have used Param Value = "blue" . Now in Applet, I will store the Param Value into one string called String s. In Applet,I have color object called Color c and Label Object label. Now I want to set the Background color of the label object. So can I used: label.setBackground(Color.s) where s is the string which has param value of html. OR Is there any other alternate way through with I can get the color value from HTML and set it to color object. Please let me know, Thanks Angela
Arun, Unfortunately, your solution would ignore Color.black ( One of myfavourite colors for web backgrounds! )... This is due to the fact the switch() statements can only take arguments that are comparable to int... so you have to use chars instead of Strings... Strings could be used if you used cascading if..else statements... but that may get a little messy... my solution would be to pass the color into the applet as RGB values and then use these to set the color... This requires you to have parameters going into your applet like BackgroundR, BackgroundG, and BackgroundB for each color you want to use, but I think it is an easier solution to code and makes the applet more modifiable...
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Why not use reflection to set up a Map which maps color names to Color objects?
As you see in the main() method, a Color may be accessed via colorMap.get(colorName). Of course you'll want to check if this is null, indicating the color name does not match an existing color. [This message has been edited by Jim Yingst (edited April 18, 2001).]