Java Reference
In-Depth Information
FigurePanel
Panel with
FlowLayout
F IGURE 17.18
The program displays lines, rectangles, and ovals when you select a shape
type.
Traffic light
panel
Panel with
FlowLayout
F IGURE 17.19 The radio buttons are grouped to let you select only one color in the group to
control a traffic light.
Sections 17.6-17.8
**17.4
( Text viewer ) Write a program that displays a text file in a text area, as shown in
Figure 17.20a. The user enters a file name in a text field and clicks the View button;
the file is then displayed in a text area.
(a) (b)
F IGURE 17.20 (a) The program displays the text from a file in a text area. (b) The program
displays a histogram that shows the occurrences of each letter in the file.
**17.5
( Create a histogram for occurrences of letters ) The program in Listing 17.8,
MultipleWindowsDemo.java, displays a histogram to show the occurrences of
each letter in a text area. Reuse the Histogram class created in Listing 17.9 to
write a program that will display a histogram on a panel. The histogram should
show the occurrences of each letter in a text file, as shown in Figure 17.20b.
Assume that the letters are not case sensitive.
Place the panel that will display the histogram in the center of the frame.
Place a label and a text field in a panel, and put the panel in the south side of the
frame. The text file will be entered from this text field.
Pressing the Enter key on the text field causes the program to count the occur-
rences of each letter and display the count in a histogram.
Search WWH ::




Custom Search