Introduction to Computer Science II by James Tam Return to the course web page

CPSC 233: Assignment 6 (Worth 6%)

 

Due Friday December 10, worth 6% of overall grade

New Concepts to be applied for the assignment

How to implement a graphical user interface with Java1:

  1. Frames
  2. Lists
  3. Classes that handle layout (e.g., GridBagLayout)
  4. Textfields
  5. Labels
  6. Buttons
  7. Listener classes (e.g., ones that implement ActionListener)

File-based input and output:

  1. FileReader
  2. BufferedReader
  3. FileWriter
  4. PrintWriter

Creating a simple graphical user interface

For this assignment you are to implement a simple GUI (graphical user interface) that allows a person to manage a list of email contacts1

The full program will read the information about the contacts from a text file called "inputContacts" and display this information in a graphical list.  The user will have the ability to add a new contact or delete an existing contact.  At any time the user can write the updated contact list to another text file called "outputContacts".  (To simplify the marking of assignments make sure that you use these exact file names).  When the user is finished working with his or her contacts list, the program can be shut down by closing the window.

 

Grading

 

Base grade levels

D-

Student has invested considerable effort in the assignment but the code won't compile.

D

Student has invested considerable effort in the assignment.  The program compiles but does not fulfill any of the requirements listed  below.

C-

When the "load" button is pressed, the program reads the information for the list of contacts from a file called "inputContacts".  (Again you must use this file name otherwise your TA will have a hard time figuring out what name that you used slowing down the marking process).   The list of contacts will be displayed in the list.   

 

 

Additional features:

Implementing each of the features listed below will result in a grade increase of one letter "step" for each feature implemented up to +a maximum grade of A+.  Except as noted below you are free to implement the features in whatever order that you desire.

1

The window can be closed by pressing the close window control at the top right hand side of the window.

2

The user can remove a contact from the list by selecting the contact and pressing the remove button.

3

When the list is empty, the remove button is disabled.  You must have implemented feature 2 prior to implementing this feature (so that you can first make the list empty).

4

Text that is entered into the text field will be added to the list as a contact when the add button is pressed.

5

Text that is entered into the text field will be added to the list as a contact when the cursor (focus) is in the text field and the user hits return.

6

The title bar indicates to the user that the list changed: when a new contact was added or when an existing contact was removed (features 2, 4 & 5 must be implemented prior to implementing this feature).  The message in the title bar will remain for a few seconds and then the text in the title bar will revert back to what was originally there.  Because you won't have learned how to write a timer, the interface will "lock" during this period of time and will not accept any input from the user.

    7 The "save" button will write the current state of the contacts list to a file called "outputContacts".  (Again you must use this file name otherwise your TA will have a harder time figuring out what name that you used slowing down the marking process).   This file will be identical to the input file if the user has not made any changes to the list of contacts since it was loaded from the input file.  Changes that were made by the user since loading up the contacts list will be saved to the output file.

8

The program won't add "empty" contacts to the list.  If the text field doesn't contain any text when the add button is pressed or when the user hits return, then nothing will be added to the list.  An error message will be displayed to the user for a few seconds before the original text reappears.  Again this feature must be implemented after feature 4 & 5 has already been completed.

Other submission requirements

1. Good coding style and documentation:  They will play a role in determining your final grade for this assignment.  Your grade can be reduced by a letter step or more e.g., 'A' to 'A-' for poor programming style.

2. Method of submission: You must electronically submit all your source code before the due date.  You will not need to demo this assignment to your TA.   In addition to submitting your source code you must include a 'README file..  This file must include all the pertinent information needed by your TA to mark your assignment:

Because there aren't any demos for this assignment, this README must be complete enough so that your TA can understand exactly how to run all parts of your program.

1 While you are allowed to implement your assignment using either the classes in the newer Swing packages or the older AWT packages, officially we will be providing support only for AWT.  That means that if are using SWING and get stuck then you may be one your own.  Also you need to know how the code in the AWT package works for the final exam.

 

Relevant links

  1. Sun's online AWT documentation: http://java.sun.com/j2se/1.4.2/docs/guide/awt/index.html.  Look especially at the packages: java.awt and java.awt.event.

  2. Sun's online SWING documentation: http://java.sun.com/j2se/1.4.2/docs/guide/swing/index.html