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:
Create an applet called ContactInfoFormTest that creates and displays an instance of ContactInfoForm.
Create class ContactInfoForm as a subclass of FormElement.
In the constructor, create and track references to a LabeledTextField (with argument "Name"), PhoneTextField, EMailTextField, and LabeledChoice (with argument "Payment Method").
Add the components in such a way that they are arranged with one on top of the other in the order specified above.
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).
Define the method getContents such that it returns a newline-separated list of the contents of the subelements.
Define method isEmpty such that it returns true if any of the subelements are empty, else return false.
Define method verify such that it asks each subelement to verify itself.
Required by
Related Exercises
|