Assignment Overview:

This assignment requires you to do supply a GUI front end for the classes that you wrote for Assignment 1. The theme will be Customers, Staff and Items. Note that this is a programming exercise only. It is designed to test your understanding of various aspects of Java programming. It is not intended to be a model of what happens in the real world – so don’t go changing things because “it makes more sense”.

You will be required to develop your application using Java in the Eclipse environment. You will need to zip the whole project up when you are finished and submit it electronically by the due date. You will also need to submit a report (both electronically and as a hard copy).

Task 1

Create a new project in Eclipse called ‘Assignment 2’.

Create a package called ‘people’ within this project. Download the start up classes and put them into this package. These classes are similar to the ones you wrote for assignment 1 but they have been modified somewhat, so make sure you use the ones provided.

Create a second package called ‘task01’. Within this package provide classes which perform the following tasks.

TestUniApplication.

  • Create a class, called TestUniApplication, that causes a JFrame window to appear when the application first starts. The window, that appears when the program is executed, should be appropriately sized, titled and located on the screen. The class should have a private instance variable of type Vector (not ArrayList) called customers.
  • Provide a menu, called Customers, with the following menu items
    • Add Customer
    • List Customers
    • Exit
  • Provide the following functionality when each of the menu items is selected
    • Add Customer – a modal dialog box, called AddCustomer, should appear. The details for this dialog box appear below.
    • List Customers – a modal dialog box, called ListCustomers, should appear. The details for this dialog box appear below.
    • Exit – the application will close.
  • Provide a pushbutton, called Exit, which provides the same functionality as the menu item with the same name.

Add Customer Dialog

  • This dialog should be modal and appear when the Add Customer menu item of TestUniApplication is selected. It should be appropriately located, sized and titled.
  • Provide text fields to provide enough information to create a Customer object. This should include the Customer's Name, Address but not the Customer ID. It should not include items ordered at this stage. Each of the text fields should be appropriately labelled. Furthermore, the setting out of the controls on the window should be aesthetically pleasing (it should look good). The BoxLayout and GridLayout might be able to help you with this.
  • Provide a button called save, in the south of the dialog. When this button is clicked the information in the textfields is used to create a Customer object. The Customer Id should be calculated as the number of customers currently stored in the Customers Vector plus 1000. This number should be preceded by the letter ‘C’. Thus the first customer added should have the Customer Id C1000. The Customer object should be stored in the customers Vector in TestUniApplication. The window should then be disposed of allowing control to return to the TestUniApplication window.
  • Provide a second button called cancel which disposes of the dialog allowing control to return to TestUniApplication without creating a new Customer object.

List Customers Dialog

  • This dialog should be modal and appear when the List Customers menu item of TestUniApplication is selected. It should be appropriately located, sized and titled.
  • The dialog box should have similar text fields and labels to that of the Add Customer dialog.
  • A JList object should be used to enable the user to view a list of Customer objects currently in the customers Vector.
  • When an item in the List is selected, the details associated with that Customer should be used to populate the text fields in the dialog.
  • Provide the following pushbuttons in the south of the window
    • Save – will enable any updates to the text fields to be saved to the appropriate Customer. Thus if the customer Fred changes his name to James then the save button will save this change and the next time the list opens this change should appear.
    • Cancel – will dispose of the window returning control to TestUniApplication.

Task 2

Create a third package called ‘task02’. Copy the TestUniApplication, AddCustomerDialog and ListCustomerDialog across to this new package. Make the following modifications to TestUniApplication

  • Provide a second menu called File with the following menu items.
    • A menu item called save. When this item is selected, the whole Vector is stored to a file using serialisation. Use a FileChooser object for this. The starting directory for the FileChooser object should be c:\input.
    • A menu item called open. When this item is selected, a FileChooser object appears which enables the user to open a file that was previously save (using the ‘save’ button). The Vector object should be read from the file, and its contents added to whatever is currently in the main Vector collection.
    • A menu item called empty that will remove all Customers currently in the Vector. A message box should appear to confirm with the user if this is the action they want taken.

Make the following modifications to ListCustomerDialog

  • Add a new button (called remove) to remove the selected Customer. When this button is clicked a message box should appear asking whether the user is sure that they want to delete the customer. If the user selects ‘yes’ the Customer should be removed from the underlying Vector. The window should then close and control return to the main window.
  • Note that if you click the remove button with no item selected in the list, the program will crash with an ArrayOutOfBoundsException. While there are several ways of dealing with this, the program should use a try/catch block that provides a message dialog (in the handler) telling the user that an item must be selected.
Academic Honesty!
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.