Assignment #1: Colortest


Your starting point is the JAVA code of the Colortest program presented in the last lecture.
Before you go on, please download the two classes that belong to that project and put them in one folder, named 'Assignment1' OR just download the ZIP-file, unzip it: it will create the required folder including the 2 sources.

Download Colortest.java
Download ColorPanel.java
Download ZIP file

Using NetBeans, or the console-compiler or whatever you want to use, compile the sources.
Run 'Colortest', this is the main class, containing the 'public static void main...'.
You should see this output:


Your task:

Change the program to show the following window:


What is this assignment about ?

Task A:
Obviously, you have to change the output of the program in a way, that the first row consists of 1 column only, the second row of 2 columns and so on. Hence you have to understand the code to find the output loop to make the change.

Task B
Now, since we only need 1 column in the first row, 2 in the second etc., it is a waste of memory to store the whole color rectangle, including all the color-cells in the upper right triangle that are not shown. As memorized in the lecture, JAVA 2D arrays (being arrays of arrays, remember ?) offer the possibility to define 2D arrays having rows of different length, thus creating a datastructure that takes exactly as much memory as needed. Therefore, part B of your task is:
change the definition and initialization of the array in a way, that IN THE DATASTRUCTURE ITSELF the first row only contains one column, the second 2 etc.


Hints:


Scores:

Task A, the pure output change: 3 points.
Task B, changing the datastructure: 7 points
Bonus: 1 point for the bonus task (see below)


Bonus Task

Change the background of the upper right triangle to blue. This can be done in multiple ways, but the easiest is a straightforward usage of the rectangle drawing command that is already used in the program.


If you a interested further ...

...even without bonus points:
You might want to play with the colors. The output colors are defined by their red, green and blue values. Changing these values changes the output colors - e.g. try to add blue and see what happens (you should play with the original version, not the modified triangle version. The full color rectangle looks much better).


GOOD LUCK !