logo CodeStepByStep logo


Write a complete program named ColoredWindow with a graphical user interface that allows the user to set the background color of a window by typing in the name of a color into a text field and pressing Enter. You should look up the red/blue/green values for a particular color from a given text file named colors.txt, which contains the name of a color on one line and the values of the red/green/blue components for that color on the next line. (The data in this file comes from an experiment done by the web comic xkcd where many people were shown pictures of colors and asked to name them.)

To create a Color out of its red, green, and blue components, you can use the Color constructor by writing new Color(r, g, b). To avoid reading the file every time the user types in a color, store the colors in an appropriate data structure. If the name the user entered is not found in colors.txt, your program should do nothing. Here is an example of the contents of colors.txt:

pastel blue
72 100 175
baby blue
182 226 245
130 64 234
75 49 234
olive green
111 145 122
...and so on...

This exercise does not have any test cases associated with it. You can look at this exercise and try to write your own solution on your computer in a text editor, but you cannot submit it here for testing. We're sorry for the inconvenience.

Need help?

If you do not understand how to solve an exercise or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect tests, etc.), please

Is there a problem? Contact a site administrator.

©, all rights reserved.