Java Reference
In-Depth Information
to scale up or down by one point at a time. Start with a default font size of 9 points. As you scale
up, you'll be able to see the holes in the letters more clearly. As you scale down, the holes will be less
apparent. What is the smallest font size at which you begin to notice the holes?
12.20 (Typing Tutor: Tuning a Crucial Skill in the Computer Age) Typing quickly and correctly
is an essential skill for working effectively with computers and the Internet. In this exercise, you'll
build a GUI application that can help users learn to “touch type” (i.e., type correctly without look-
ing at the keyboard). The application should display a virtual keyboard (Fig. 12.50) and should al-
low the user to watch what he or she is typing on the screen without looking at the actual keyboard .
Use JButton s to represent the keys. As the user presses each key, the application highlights the cor-
responding JButton on the GUI and adds the character to a JTextArea that shows what the user has
typed so far. [ Hint: To highlight a JButton , use its setBackground method to change its background
color. When the key is released, reset its original background color. You can obtain the JButton 's
original background color with the getBackground method before you change its color.]
Fig. 12.50 | Typing tutor.
You can test your program by typing a pangram—a phrase that contains every letter of the
alphabet at least once—such as “The quick brown fox jumped over a lazy dog.” You can find other
pangrams on the web.
To make the program more interesting you could monitor the user's accuracy. You could have
the user type specific phrases that you've prestored in your program and that you display on the
screen above the virtual keyboard. You could keep track of how many keystrokes the user types cor-
rectly and how many are typed incorrectly. You could also keep track of which keys the user is hav-
ing difficulty with and display a report showing those keys.
 
Search WWH ::




Custom Search