Java Reference
In-Depth Information
**16.11
( Create a histogram for occurrences of letters ) Write a program that reads a
file and displays a histogram to show the occurrences of each letter in the file,
as shown in Figure 16.40b. The file name is entered from a text field. Pressing
the Enter key on the text field causes the program to start to read and process
the file and displays the histogram. The histogram is displayed in the center of the
window. Define a class named Histogram that extends Pane . The class con-
tains the property counts that is an array of 26 elements. counts[0] stores the
number of A , counts[1] the number of B , and so on. The class also contains a
setter method for setting a new counts and displaying the histogram for the new
counts .
*16.12
( Demonstrate TextArea properties ) Write a program that demonstrates the
properties of a text area. The program uses a check box to indicate whether the
text is wrapped onto next line, as shown in Figure 16.41a.
(a)
(b)
F IGURE 16.41
(a) You can set the options to enable text editing and text wrapping. (b) The program displays a table for
monthly payments and total payments on a given loan based on various interest rates.
*16.13
( Compare loans with various interest rates ) Rewrite Programming Exercise
5.21 to create a GUI, as shown in Figure 16.41b. Your program should let the
user enter the loan amount and loan period in the number of years from text
fields, and it should display the monthly and total payments for each interest
rate starting from 5 percent to 8 percent, with increments of one-eighth, in a
text area.
**16.14
( Select a font ) Write a program that can dynamically change the font of a text
in a label displayed on a stack pane. The text can be displayed in bold and
italic at the same time. You can select the font name or font size from combo
boxes, as shown in Figure  16.42a. The available font names can be obtained
using Font.getFamilies() . The combo box for the font size is initialized
with numbers from 1 to 100 .
VideoNote
Set fonts
(a)
(b)
F IGURE 16.42
You can dynamically set the font for the message. (b) You can set the alignment and text-position properties
of a label dynamically.
 
Search WWH ::




Custom Search