to use object-oriented programming concepts to build an application.
to implement graphical user interface program in Java.
Your task for this question is to write a simple Java program for a GUI for a telephone book application, as shown in Figure 3 below. You are also given the Contact class, the TelephoneBook class and two partially completed classes: Q3 and Q3Frame in Appendix C.
(a) Complete the class Q3 to perform the following actions:
Set the title of the frame to My Telephone Book
Set the size of frame to 550 by 250
Make the frame visible.
(b) Add Java code to the constructor of the class Q3Frame to perform the following actions:
Create the various components: labels, textfields, textarea and buttons and use containers and layout managers to position the components as shown in Figure 3.
Include your name and student number as a label in the frame.
Add a scrollbar to the text area taMessage and set its preferred size to the dimension: 400 by 100.
Set the buttons to add and remove contacts to disable and the textfield for telephone to non-editable.
Set the size of frame to 550 by 250.
(c) Add Java code to the class Q3Frame to perform the following event handling for events arising from these components:
textfield for name When user hits the ENTER key on this textfield, the event handler checks that the name field has been filled. If so, it locates the contact in the telephone book and fills up the telephone number textfield with the located contact, if the contact exists. In addition, it enables the remove button. If the contact does not exist, a message shows up in the textarea to inform user that the name is not in the telephone book yet and the add button is enabled.
If user hits the ENTER key on the textfield for name without entering any letters, the handler should inform the user that the name textfield had not been filled.
button for adding a contact The handler checks that both textfields are filled. If not, the textarea should display messages, one for each field that has not been filled up. If both fields are filled up, the handler should add the new contact, display a message to inform the user that the add has been successful and clear the date fields. The add and remove buttons are also disabled and the telephone textfield is made non-editable. However, if the contact already exists, the handler should display an error message.
button for removing a contact The handler checks that the name textfield is filled. If not, the textarea should display an error message. If the field is filled up, the handler should remove the contact with the specified name, display a message to inform the user that the remove has been successful and clear the date fields. The add and remove buttons are also disabled and the telephone textfield is made non-editable. However, if the contact does not exist, the handler should display an error message.
button for listing all contacts The handler should clear the date fields and display the contacts in the textarea. The add and remove buttons are also disabled and the telephone textfield is made non-editable.
button for clearing data fields The data fields as well as the textarea are cleared. In addition, the add and remove buttons are disabled and the telephone textfield is made non-editable.
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference
and should not be submitted as is. We are not held liable for any misuse of the solutions.
Please see the frequently asked questions page
for further questions and inquiries.
Kindly complete the form.
Please provide a valid email address and we will get back to you within 24 hours.
Payment is through PayPal, Buy me a Coffee
or Cryptocurrency.
We are a nonprofit organization however we need funds to keep this organization operating
and to be able to complete our research and development projects.