HI! I want to write a constructor that will make a window (a frame). I want to be able to insert the height, width, position and window color. This is what I've written:

public Window(String name, int height, int width,String c,String isActive,int PointX, int PointY){






My problem is that when compiling, I get a message "could not find symbol-variable c". So I can't figure out how to declare the color that I want my window to be. Does anybody know how to do this?

4 Years
Discussion Span
Last Post by ambageo

I see what you are trying to do. You are trying to access the static members of java.awt.Color such as Color.red or Color.blue except that you are trying to do it with a String that contains the words "red" or "blue". You cannot use the dot notation that way, and in general you cannot ever just substitute a String in place of the text that it contains in Java. Accessing fields using a String containing the name of the field would only be possible using reflection, but you would be far better to pass a Color into your constructor rather than a String.

If you must take a color name rather than a color, then I would use a java.util.Map<String,Color> to build up a library of as many colors as I liked and do the conversion that way. There is also Color.getColor(String name) which allows colors to be accessed by name from system properties.


Thanks for the response! I'll see what I can do with the Color.getColor(String name)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.