CPSC 170 Postlab 4: Changing Colors

Your assignment is to create a GUI that provides radio buttons to let the user change the background color. Your GUI should provide a heading, e.g. "Pick a color", and a set of radio buttons, each of a different color. When the user presses, say, the yellow radio button, the background of the entire GUI should change to yellow. Provide at least 5 different color choices.

General Structure

You will need two files, a driver and a class with the code for the GUI. The driver will be very much like the StyleOptions class you used in the lab. The GUI code will be similar in structure to the StyleGUI class, but you will use an array of radio buttons to provide the color options to the user. You will also need an array of colors to store the color associated with each radio button -- it's probably easiest to initialize this with an initializer list when you declare it. Then after you create the heading, set up the panel to hold everything, create a group, and create a listener object (more on this below), you will need to set up the radio buttons. For each radio button (that is, each array element), you will need to create the radio button, add it to the group, make the listener object listen on it, set its background color to the appropriate value, and add it to the panel.

The Listener Class

Radio buttons need an ActionListener, so you will need to set up a private class that implements the ActionListener interface, much as in the StyleGUI class. In the listener you can just run through the array checking for the selected button, then set the background color of the panel appropriately when you find it.

What To Turn In

Turn in hardcopy of your GUI and driver classes. Tar your post4 directory and e-mail it to me with cpsc170 post4 in the Subject line.