The size of your applet in the HTML file should be large enough to display the ColorCreators
at their natural size (my applet is 550 wide x 325 high).
The main part of this assignment is for you to create
the ColorCreator class.
The Applet
All of the code for the applet can be put in the init method.
As you can see above, the applet uses a FlowLayout.
First is an instance of the ColorCreator with a HORIZONTAL alignment,
then a JButton, then another JButton, then a ColorCreator with
a VERTICAL alignment.
When you click on the first JButton, its background color should change
to the current color of the top ColorCreator (using the getCurrentColor
method of that ColorCreator).
When you click on the second JButton, the color of the top ColorCreator
should be changed to the color of the bottom ColorCreator (using the getCurrentColor
method of the bottom ColorCreator and the setCurrentColor method of the top
ColorCreator).
Make sure that the initial (background) color of the first JButton is the current color
of the top ColorCreator. The background color of the second JButton never changes from white.
The ColorCreator is divided into two parts
(see the two ColorCreators at the bottom of the
ColorCreator interface page,
which makes this fact more obvious):
the first part is a JPanel containing three other JPanels, each of which contain
a JSlider and a JTextField. Each of these three JPanels uses a
BorderLayout with the JSlider in the Center region and the
JTextField in the East region.
the second part contains a JPanel, which displays the current
color, and a JPanel, which contains the nine JButtons.
There are three ways to change the current color: by moving
the knob on one of the JSliders, by entering a number in
one of the JTextFields, or by clicking one of the nine JButtons.
If you change things using one of these, then all of the Components
(all of the JSliders and JTextFields) should reflect this change immediately.
In my program I did this by having an update
method to which I sent a Color, and then the update method
set the JSliders and JTextFields to the RGB values of that
Color, and displayed the new color in the JPanel which displays the
current color.
Experiment with the ColorCreator above to see this.
This is an important feature of the ColorCreator.
The middle JButton causes a random color to be created.
Try clicking it a few times to see how this affects things.
If the user enters anything other than an integer in
a JTextField, then a 0 is simply put there (this is done
via exception handling, that is, using a try-catch block).
Try this in the applet above.
If an integer is entered that is less than 0, simply
replace it with 0. If an integer is entered that is greater than 255,
simply replace it with 255. Try this in the applet above.
Paint a black frame (of let's say 2 pixels in width)
around the JPanel that is being used to display the current color.
I think that this makes it look a little nicer.
The files to submit
ColorCreator.java
ColorCreator.class
homework3.java
homework3.class
homework3.html
At the top of your .java file, be sure to include your
name,
login ID,
student number,
assignment number, and the
honesty pledge.
Clarifications and answers to specfic questions from students