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

FormElement

Prerequisites

  • None

All input elements of the RegistrationForm applet have some common behavior. In this Exercise, you will create an abstract class that defines this common behavior and handles events to manage input element validation. FormElement is the superclass of all elements:

Each element knows how to answer isEmpty, getContents, and verify.

The phone number and email address of your applet should be verified for correctness--the method verify should be called for each element, defaulting to an empty method if verification makes no sense for that element. Verification is to occur when the user leaves the element by clicking outside that element. To achieve this, you will have to define handleEvent so that it catches Event.LOST_FOCUS and Event.ACTION_EVENT (in case they press Return in a TextField, for example). See PhoneTextField and EMailTextField for more on verifying these fields.

Perform the following tasks:

  1. Declare the abstract class FormElement to be a subclass of Panel so that it can act as a Container.
  2. Define method public boolean isEmpty to return false.
  3. Define an abstract method public String getContents.
  4. Define method public void verify to do nothing.
  5. Define method public boolean handleEvent. Upon LOST_FOCUS or ACTION_EVENT events, it should call verify on the element itself unless the element is empty.
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

  • None