Technical Support
Discussion Forum
Online Training
Read About Java
Java In-Depth
Product Discounts
Membership Information

Java Cup Logo

JDC Home Page


Working Applet
Help and Hints
Source Code
Table of Contents
Online Training
shadowSearchFAQFeedback

PhoneTextField

Prerequisites

In this Exercise, you will subclass an existing compound component, LabeledTextField, to perform validation of the user entries upon an ACTION_EVENT or a LOST_FOCUS event (remember that FormElement will call verify upon these events). This will be used in the main RegistrationForm as a way to validate input on the client side.

Other examples of creating your own components can be found in EMailTextField and LabeledChoice.

Perform the following tasks:

  1. Create an Applet to hold one instance of PhoneTextField so that you can test your component.
  2. Create the class PhoneTextField as a subclass of LabeledTextField. Make the constructor set the label to "Phone Number".
  3. Override the method verify of FormElement so that an error is printed if the text contains any nondigits or does not have the right number of digits (either 7 or 10). Set the text to "" upon error.

The task numbers above are linked to the step-by-step help page. Also available is a complete solution that meets these requirements.

Required by

Related Exercises