Question: GUI Lab Write a Java program which will use a graphic user interface to look up the phone number associated with a specific name and

GUI Lab

Write a Java program which will use a graphic user interface to look up the phone number associated with a specific name and vice versa. This program will be broken up into two parts, the back end and the front end. The back end component of this lab will consist of reading a list of names and numbers from a file and storing the information into Binary Search Trees. The front end component will consist of presenting the user with a graphical user interface to search the data.

To implement this program, create a Java class called Phonebook. The Phonebook class must subclass the JFrame class. The Phonebook object should have two instance variables: two TreeMap objects named names and numbers. (A third instance variable, serialVersionUID may be automatically generated using Eclipse and is optional) When defining and initializing TreeMap objects we must specify a data type for the generic data types Key and Value. For both instance variables the Key and Value data types must be type String.

In the Phonebook class, define a parameterized constructor which takes a single parameter of type File. The given text file will contain name and number information, where each line of the file contains the information for a single person and their corresponding phone number. The name and number will be separated by a , character. For example, a line of text would look like:

Leslie Cortez,1-515-718-4932

When the parameterized constructor is called, it should populate the names and numbers instance variables with these values. TreeMap objects store a key value pair. To add a new key value pair to a TreeMap object, use the put method, which takes two parameters one of type Key and one of type Value. (These are generic types and in for this lab, the data type for both Key and Value should be String) The names instance variable should use the name as the key and the number as the associated value. The numbers instance variable should use the number as the key and the name as the associated value.

The parameterized constructor should also configure the Phonebook frame. Phonebook should have a height of 70 and a width of 670. The resizable property should be set to false and the default close operation should be set to JFrame.EXIT_ON_CLOSE

The Phonebook frame should contain a single panel with four components: two JTextFields of length 15 and two JButtons with text Get Number and Get Name respectively. The first text field will be used to input and display names, the second text field will be used to input and display numbers. The resulting GUI should look like the following image.

Both buttons should implement Action Listeners. The Get Number button should have an action listener which:

Gets the String in the name text field

Check if the name exists in the names TreeMap instance variable

If it does not exist, set the number text field to NO NUMBER

If it does exist, set the number text field to the number associated with the parsed name

The Get Name button should also have an action listener. The Get Name buttons action listener would have the same behavior as described above except it would get the String in the number text field, check if that number exists in the numbers TreeMap, and update the name text field. If the number was not found in the numbers TreeMap, then the name text field should be set to NO NAME

NOTE: The only method your program is required to have is a parameterized constructor. Although you can implement all of your programs behavior in that single method, I recommend creating helper methods to keep your program organized and readable.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!