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

ContactInfoForm

Prerequisites

In this exercise, you will write class ContactInfoForm and a test applet that collects contact information from the user: name, phone, email address, and payment method. The class ContactInfoForm is a FormElement that contains LabeledTextField, PhoneTextField, EMailTextFIeld, and LabeledChoice compound components arranged in a column.

To satisfy the FormElement identity, ContactInfoForm must answer isEmpty, getContents, and verify. Because this element contains four other elements, the FormElement methods must collect information from each subelement to answer.

Perform the following tasks:

  1. Create an applet called ContactInfoFormTest that creates and displays an instance of ContactInfoForm.
  2. Create class ContactInfoForm as a subclass of FormElement.
  3. In the constructor, create and track references to a LabeledTextField (with argument "Name"), PhoneTextField, EMailTextField, and LabeledChoice (with argument "Payment Method").
  4. Add the components in such a way that they are arranged with one on top of the other in the order specified above.
  5. Define the method public Dimension preferredSize so that it returns a width of 300 pixels and a height of 120 (30 pixels for each field).
  6. Define the method getContents such that it returns a newline-separated list of the contents of the subelements.
  7. Define method isEmpty such that it returns true if any of the subelements are empty, else return false.
  8. Define method verify such that it asks each subelement to verify itself.

Required by

Related Exercises