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

CPSC 233: Assignment 6 (Worth 6%)

 

Due Friday April 16.

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 contacts.  You are allowed to use the classes in either the AWT or the Swing library.  If you implement your assignment using the Swing library be sure that you know how the AWT classes work for the final exam.

The full program will read the information about the contacts from a text file called "contacts" and display this information in a graphical list.  The user will have the ability to add a new contact or delete an existing contact.  When the user quits the program by closing the window the updated contact list will be saved into another text file called "updatedContacts".  (To simplify the marking of assignments make sure that you use these exact file names).

 

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.

D+

Program is an "empty" GUI.  While you do not have to use one of the layout manager classes for this assignment, all the components are laid out neatly but none of the functionality has been implemented e.g., pressing a button does nothing.  

C-

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

C

Program reads the initial information for the list of contacts from a file called "contacts".  (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.    Your program will automatically load in the list of contacts from file, there is no need to implement another control (such as a "load" button) to do this.

C+

As the window closes (as per the functionality implemented in the "C-" level assignment) the program will write the current contents of the list to a file which must be called "updatedContacts").

 

 

Additional features:

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

1

The user can remove contacts from the list by selecting it from the list and pressing the remove button.

2

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

3

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

4

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

5

The title bar indicates to the user that the list changed - it indicates when a new contact was added or when an existing contact was removed (features 1, 3 & 4 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.

6

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 3 & 4 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: Do not hand in a paper typescript of this assignment.   Instead you must electronically submit all your source code before the due date.  There will not be a need to demo this assignment to your TA.   In addition to submitting your source that you include a file called "README".  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.

 

New Concepts to be applied for the assignment

How to implement a graphical 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

1While 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.

 

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