CSC 171 : Chapter 11 Lab : DRAWING IN COLORS
Due March 23rd, 9PM
This lab is based on Deitel & Deitel excercises 11.13, 11.14, 11.15, & 11.16. While it is possible to do all 4 steps all at once, it is highly recommended that you proceed through the steps one at a time adding functionality with each step.
Step 1 : (ex 11.13) Write a color chooser applet that provides three Scrollbar objects and three TextField object. Each Scrollbar represents the values from 0 to 255 for the red, green and blue parts of a color. Use the red, green and blue values as the arguments to the Color constructor to create a new Color object. Display the current value of each Scrollbar in the corresponding TextField. When the user changes the value of the Scrollbar, the TextField should be changed accordingly. Display the current Color value on the applet by drawing a filled rectangle. In order to do this, you will need to define your applet and a class implementing AdjustmentListener.
Step 2: Modify the applet of Exercise 11.13 to allow the user to type an integer value into a TextField to set the red, green, or blue values. When the user presses Enter in the TextField, the corresponding Scrollbar should be set to the appropriate value. This can be done by having your applet implement ActionListener, by adding action listeners to the TextFields, and writing the actionPerfomed method.
Step 3. Modify the applet of exercise 11.14 to draw the current color as a rectangle on an instance of a subclass of Canvas. The subclass of Canvas should provide its own paint method to draw the rectangle and should provide set methods to set the red, green and blue values for the current color. When any set method is invoked for the subclass of canvas, the object should automatically repaint itself.
Step 4. Modify the applet of exercise 11.15 to allow the user to drag the mouse across the canvas to draw a shape in the current color. Enable the user to choose what shape to draw.