Assignment 2: The Beauty of Colors


Description

This is not your usual programming assignment, since most of the programming work is already done by me, hurray! But, this time it's about understanding how to override a method, and to see the effects. It also might be the first time you program graphics in JAVA, without the slightest need to know anything about it. In short: this assignment is to let you experience the convenience of inheritance.

The specific objectives of the assignment are:

Task #1:
Create a Netbeans project and import the following class:

Build your own Class, and instantiate an object of type "ColorPanel". Mysteriously, the following window appears on the screen:

Task #2: (5 points)
Look at the code of ColorPanel, and understand its structure; understand what kind of object ColorPanel is. This is the first time you see a graphical element in this class, i will talk about these topics later. For now, just understand that you CAN use classes of the package javax.swing, no need to deeply understand how, yet. (again: we will go into detail later). To understand the program, use the debugger of Netbeans and single-step through the code. As a proof that you are able to use the debugger, i want you to generate a screenshot (alt - printScreen) of the debugging process after the following state: please set a conditional breakpoint in the loop that generates the colors. Set the condition such that the debugger stops in the 6th row (r==5). Bring the tab showing Local Variables to the front and create the screenshot. Send a jpeg of that shot to the TA. To prove ownership, enter your name as a comment line in the source code before you take the screen shot.

Task #3:(5 points)
In your own class, OVERRIDE the "getColor()" method of ColorPanel. "getColor()" returns a Color object, which you have to compute in your own little method. Be creative! The following output was created by changing a single line in the code from the original getColor method, setting 'blue' to a random value, instead of 0   (random values in JAVA are created using Math.random(), which returns a double value between 0 and 1) :

About Colors: Colors in JAVA are following the RGB model (Red,Green,Blue). As you might remember from mixing water-colors in Kindergarden, there are primary colors, which, mixed together, result in others. Very similar here (yet the underlying physical model is different: we have the additive color mode here, not the subtractive one): the basic colors are red (r), green (g) and blue (b), and a single color is defined in java by assigning portions of these, by giving values between 0 and 255. Example: RED: r=255, g = 0, b = 0. BLACK: r=g=b=0. White: r=g=b=255; gray: r=g=b=127; orange: purple: r=255, g=0, b=255; Temple's official 'CHERRY' color: r=163, g=38, b=56.

Deadlines: the assignment is due Tuesday, September 11, 10pm. Handing in the assignment later, you can only reach a max. score of 6 points. Absolute deadline: Thursday September 18. After that, no points are given. You have to send the code and the debugging screenshot to the TA.