RBG: How They Add Up

Motivation: This assignment gives practice with GUI programming in the context of the objectdraw system. Specifically, it uses buttons, labels, and a text field, and the flow layout and border layout managers, along with the objectdraw canvas, which responds to key input. (Mouse response could easily be added as before.) These elements can be combined to satisfy a wide range of game programming needs, while avoiding the worst of the complications in the GUI world. Playing with the program developed in this assignment also gives a feel for the RGB color system.

Assignment

Implement a FrameWindowController class named Rgb with behavior similar to rgb.jar. To try the demo jar,, download it and double click it, or run it with the shell command java -jar rgb.jar.

The buttons are used to select one of the three primary additive colors. The amount of each of these colors in indicated by the corresponding colored rectangle, and the result of adding them together is displayed in the right-most rectangle. The selected primary color's value, in the range of 0 to 255, is displayed in the text box. A brief usage message appears at the bottom of the screen.

The value of the selected primary color may be changed either by editing the text box contents (and pressing return), or with the up and down arrow keys. Changes made with the arrow keys are reflected immediately in the text box. Try holding down an arrow key for rapid changes in the smallest possible steps.

If a number out of the range of 0-255 is entered, it is ignored and the previous value is restored. If characters that do not represent an integer are entered, an error message appears in the interactions window and the bogus string is left in the text box, but the color values do not change and the program may still be used.

Use the GuiDemo program presented in class as a guide for how to combine the various GUI elements and provide their handlers. You may wish to use an instanceof expression, but it is not essential.

Design your program before attempting to type code! Write pseudo-code in comments and refine it in stages until it reflects in detail what every line, or small number of related lines, are doing. Only then translate your ideas into code.

Test your design using use-case scenarios. That is, think of as many different ways as possible in which the user will interact with the program, and see in detail that your design will do the right thing in each case. Do this before coding.

As always, use good programming style (e.g. no magic numbers), and develop and test the program in stages.

To give you an idea of how much code is required, a sample solution with good style has 170 lines, 13 of which are constant declarations. A number of lines were copied with little or no change from the GuiDemo program.