![]() ![]() ![]() |
|
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
With this exercise, you will complete a phonebook look-up applet. The skeleton code creates a GUI that consists of a pull-down list of names, a text field for entry of a phone number to look up, and a command button to activate the look-up operation. It is your job to add the event handling to the applet. There are three different events that must be handled. When the user changes the name in the pull-down list, the applet should look up the appropriate telephone number in the phonebook. When the user enters a phone number in the text field and presses return or selects the button, the applet should look up the number in the reverse phonebook and change the name in the pull-down list. Finally, the applet should restrict input in the text field to digits and the '-' character. If a look-up operation fails, the applet should simply beep. The actual telephone book appears below:
PrerequisitesSkeleton Code
Tasks
To handle selections in the
Register the
To handle text entry and the look-up operation for the telephone number,
design a class that implements
Instantiate the class (once) that implements
To restrict input in the
To ensure errors can be deleted and retain normal functionality for the Enter
and Tab keys, let the Backspace, Delete, Tab, and Enter
keys be valid characters for the
Register the object that implements
Use the
Where help exists, the task numbers above are linked to the step-by-step help page. Solution Source
Demonstration
This exercise only runs within browsers that support the Java Runtime Environment 1.1 and appletviewer. If you are using an appropriate browser, try this exercise. The output should look similar to the following:
Next ExerciseExercisesShort CourseCopyright 1996-2000 jGuru.com. All Rights Reserved. |