Exercises for Chapter 4

4.1 Revisit the Doodle application from Chapter 2 and re-implement it to provide save under capability.

4.2 Extend the Tuttle class to provide a facility to render a String onto the drawing area at the current Tuttle location. This will also require methods to support a Font attribute to be provided.

4.3 Re-implement the Tuttle class, removing the update() method, so that the flickering effect becomes visible.

4.4 Extend the Tuttle class to produce a GeometricTuttle class which has the capability to draw rectangles, polygons, ovals, arcs, etc.

4.5 The execution of the Tuttle setBackground() method can take some time even on a fast machine. One way to avoid the usability problems caused by nothing apparently happening is to process the image one row at a time. This will take longer but the user will see the background changing slowly from the top to the bottom of the drawing. Reimplement the setBackground() method making use of this technique.

4.6 Design and implement a ColorValue applet which contains three Scrollbars, a Canvas and a Label. The user should be able to interactively use the sliders to indicate the red, blue and green components of a color. The applet should respond by filling the Canvas with the specified color and the Label should display the hexadecimal RGB values.

4.6 Implement an image processing class. This class should be capable of loading an image from a GIF file and then applying various filters to it. For example a color can be converted to its grey scale equivalent using the formula GG = (RR + GG + BB) / 3 and then setting the RR, GG and BB bytes to GG. A cut off filter can then be produced which converts all pixels above a certain GG value to black and all below it to white.

4.7 Extend the application from 4.5 to provide an image intensity histogram. The GG value is a measure of the intensity of the pixel and has a range of 0 to 255. By counting the number of pixels from the image which have each possible intensity value and then displaying these numbers as lines of different heights an intensity histogram can be produced.

4.8 The decision not to move the tuttle beyond the bounds of the virtual space was somewhat arbitrary. Other possible decisions might have been to move the tuttle up to the limits of the space rather than to refuse to move it at all, or to allow the tuttle to get lost in tuttle space reappearing when it moves back into view or when the tuttle moves beyond the right (top) of the space to reappear on the left (bottom) of the space. Implement one, or all, of these alternative behaviours.


Table of Contents.

Summary of Chapter 4




A Java GUI programmer's primer
Java GUI Programmers Primer, A
ISBN: 0139088490
EAN: 2147483647
Year: 1998
Pages: 85
Authors: Fintan Culwin

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net