Java Reference
In-Depth Information
b. In this particular image, only about 2/3 of the shades of gray are used. For
example, if the image consisted entirely of shades in the range from 150-160
then the entire image would appear to be almost the same shade of gray. One
method to enhance such an image is to scale the shade of each pixel to the entire
range from 0 to 255. Pixels that were originally at value 150 would be drawn
with the value 0, pixels that were originally 151 would be drawn with the value
25, and so on up to pixels of the shade 160, which would be drawn with the
value 255. This technique spaces out the shading so the details are easier to see.
To compute the new shade for a pixel at coordinate (i,j) :
255 x (OriginalShade(i,j) - MinOriginalShade)
(MaxOriginalShade - MinOriginalShade)
NewShade(i,j) =
MinOriginalShade is the smallest scale of gray in the original image and
MaxOriginalShade is the largest scale of gray in the original image.
Modify your program so that the image is drawn using the scaling technique
described above. The brightness and details in the resulting image should be a
little bit easier to distinguish.
3.
Write a GUI program that uses the methods in the Graphics class to draw a smi-
ley face when the window is activated, and a frowny face when the window is
deactivated. This will require use of a WindowListener to detect the activation or
deactivation events.
4.
Write a “skeleton” GUI program that implements the WindowListener interface.
Write code for each of the methods in Display 18.1 that simply prints out a mes-
sage identifying which event occurred. Print the message out in a text field. Note
that your program will not end when the close-window button is clicked (but
will instead simply send a message to the text field saying that the windowClosing
method has been invoked). Include a button labeled Exit that the user can click
to end the program.
5.
Enhance the face drawing in Display 18.17 in all of the following ways: Add color
so the eyes are blue and the mouth is red. When the face winks, the line that repre-
sents a closed eye is black not blue. Add a nose and a brown handlebar mustache.
Add buttons labeled "Smile" and "Frown" . When the "Frown" button is clicked,
the face shows a frown (upside down smile); when the "Smile" button is clicked,
the face shows a smile. When the user clicks the close-window button, a window
pops up to ask if the user is sure he or she wants to exit, as in Display 18.2.
6.
Write a GUI program to sample different fonts. The user enters a line of text
in a text field. The user then selects a font from a font menu. Offer the three
guaranteed fonts and at least two other fonts. The user also selects any desired
style modifiers (bold and/or italic) from a style menu, and selects point size
from a point size menu that offers the following choices: 9, 10, 12, 14, 16, 24,
and 32. There is also a "Display" button. When the "Display" button is
clicked, the text is displayed in the font, style, and point size chosen.
Search WWH ::




Custom Search