Starting from:
$35

$29

CS326 Homework 8 Solution

Submission: along with the usual paper submission at the beginning of the class, also send an email to cs326@cse.unr.edu containing:

    • subject: HW 8
    • message body: your name
    • attachment: the electronic version of your code (preferably just one file with all classes)

  1. (100 pts) Write a Java application that implements a color sampler, with the following functionality:

• The graphical user interface is illustrated by the following picture:

  • Each color is described by its name and its red, green and blue components.

  • Colors are read from a file, with a format illustrated by the following example:

Red

255

0

0


Green

0

255

0


Blue

0

0

255


Yellow

255

255

0


Cyan

0

255

255


Magenta

255

0

255




Orange

255

100

0


Pink

255

20

145


Grey

125

125

125


Black

0

0

0


White

255

255

255




  • For the currently selected color, the three text fields show its R, G, B values, while the top component (the “color sample”) is painted with that color.

  • The currently selected color can be modified by using the + and – buttons (preferably in increments of 5). Every time such a change occurs, the appropriate text field and the color sample must also change accordingly. In addition, a "*" must be appended to the window title, to show that the current color has been modified, but not saved. The following picture illustrates the application window during such changes:

  • Pressing the Save button causes the modified values for the current color to be retained. The "*" disappears from the window title.

  • Pressing the Reset button causes the original values of the current color (or the ones last saved) to be restored. The text fields and the color sample must change accordingly. The "*" also disappears from the window title.

  • If another color is selected from the list, any unsaved changes to the current color are lost.

  • The colors (possibly modified and saved) are written back to the same file upon program termination.

More products