Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
AndrewB

Minor Moral Dilemma

Recommended Posts

AndrewB said:

People who were getting 90's and 100's in University programming classes are getting 60's and 70's in this program. Each assignment probably involves 20-40 hours of work on average. My marks are in the 85th percentile of the program. The average for our Java midterm was 53%. The 5th assignment was by far the easiest one.

There's also the fact that there are classes 31 hours a week. The next month will be 50 hour workweeks.


so your not at a university...are you at a technical or game development school? I've heard that game dev and tech schools are alot harder since most finish in two years, and its really fast paced.

dr_st said:

Hardly. When you study the first language (normally C), you get a full syntax course and then study the concepts (variables, functions, arrays, pointers). Then you learn some simple algorithms. Often there is a class which teaches you how to implement algorithms using C or C++. With Assembler it's mostly the different command types, with C++ and Java you study the basic concepts of the language (Object-Oriented Design and all other crap like that). Syntax plays a role there, naturally, but it's a minor one. After all the syntax is never too difficult to grasp. Then you probably learn about some function libraries (like MFC or the Java graphical packages, communication packages, etc).


im kind of annoyed that the school im going to (western washington university) dropped C++ and is now using ADA programming language. The stuff I've learned myself so far in C++ I have a good grasp on, but I still would have liked to take a class that teaches C or C++. Oh well, I guess I'll just use my Deitel&Deitel book.

Share this post


Link to post
Skeletor said:

so your not at a university...are you at a technical or game development school? I've heard that game dev and tech schools are alot harder since most finish in two years, and its really fast paced.

Exactly.

Share this post


Link to post

AndrewB: can you show me one of your assignments? (the assignment itself, not the solution) If you don't have it in digital format, could you at least describe it in general?

Share this post


Link to post

COSC 190 – Intermediate Programming
Assignment 4
Files
Given: Thursday, April 08, 2004
Due: Friday, April 16, 2004

You must work in pairs. Please email us your group no later than Tuesday, April 13, 2004.


This assignment will give you practice working with files as well as creating a GUI and storing values in a data structure.


This program will create a simple contact manager.
The Friend class
The Friend class will store information about one record in the contact manager:

The class has attributes for last and first name, address (street, city, province, postal code), email address, phone number, and a note (for general comments).

In addition to the get and set methods, there will be the following:
· public String getFullName() – returns a String in the format of lastName, firstName
· public int compareTo( Object o ) – compares this object to the given object on the basis of their last name values
· public boolean equals( Object o ) – for the purposes of this assignment, two Friend objects are considered equal if they have the same last name
· public String toString() – returns a String with the class name and all attribute values
· public static boolean isValidEmailAddress( String emailAddress ) – for a given non-empty, non-null string, checks that it has one and only one "@" symbol and also that it has at least one "." following the "@" symbol – if the string meets this criteria, returns true, otherwise false
· public void writeInfo( ... ) [throws IOException] – takes in a reference to a PrintWriter or DataOutputStream (depending if you decide to store info in a text file or in a binary file), and writes out each of the fields for this object to the given stream
· public static Friend readInfo( ... ) throws IOException – takes in a reference to a BufferedReader or DataInputStream (depending if you decide to store info in a text file or in a binary file), reads in the data for each field, constructs a new Friend object with these values, and returns it to the caller
The FriendFrame GUI

To create the above, define a class named FriendFrame.

Use a combination of BorderLayout, FlowLayout, and GridLayout with a number of JPanel objects to achieve the above appearance. (Hint – each label and text field above is in its own panel with a FlowLayout; and then each of these panels is a row in a GridLayout.)

The labels are JLabel objects. The text fields are JTextField objects, except the "Notes" field, which is a JTextArea in a JScrollPane, the buttons are JButton objects, and the menu is made up of JMenuItem objects added to JMenu objects placed on a JMenuBar.

The text fields above were created with the following initial sizes:

Last Name 20
First Name 20
Address 25
City 20
Province 5
Postal Code 10
Email Address 25
Phone Number 10
Note 2, 25
The frame was sized using the pack() command.

The menu choices are as follows:




The actions associated with the buttons and menus are described below.

The application can be in one of three modes (suggest having an attribute to track the mode of the application):
· Add mode – to add a new record
· All text fields are enabled
· Save button and Action | Save changes menu choice are enabled
· If there are addresses already stored in the list, the Cancel button and Action | Cancel menu choice are enabled. However, if there are no records in the list, the Cancel button is disabled.
· All other buttons are disabled.
· All other menu choices under Action and Navigate are disabled.

· Update mode – to update the current record
· All text fields are enabled
· Save button and Action | Save changes menu choice are enabled
· Cancel button and Action | Cancel menu choice are enabled
· All other buttons are disabled
· All other menu choices under Action and Navigate are disabled

· View mode
· All text fields are disabled
· The Save and Cancel buttons and the Action | Save changes and Action | Cancel menu choices are disabled
· All other buttons and menu choices are enabled


When the application first starts, the program will have an empty list.


Component Description of action
Add button
Action | Add menu choice Puts the application in Add Mode.
Update button
Action | Update menu choice Puts the application in Update Mode for the currently displayed record.
Delete button
Action | Delete menu choice Deletes the currently displayed record. If this was the last record in the list, puts the application back in Add Mode.
Save button
Action | Save changes menu choice In Add Mode, saves a new record in the list.
In Update Mode, updates the current record in the list.
In either mode, if the given email address is not valid, will display an error message and stay in the add or update mode.
Cancel button
Action | Cancel menu choice In Add Mode, returns to View Mode and displays the last displayed record.
In Update Mode, returns to View Mode for the current record (and redisplays the existing values, not any changes that were made).
<< First button
Navigate | First menu choice Displays the first record in the list.
< Previous button
Navigate | Previous menu choice Displays the record previous to the currently displayed record. If the currently displayed record is the first record, displays a message "You are at the first record" and does not navigate.
Next > button
Navigate | Next menu choice Displays the record after to the currently displayed record. If the currently displayed record is the last record, displays a message "You are at the last record" and does not navigate.
Last >> button
Navigate | Last menu choice Displays the last record in the list.
Find button
Navigate | Find menu choice Displays an input box that asks the user to enter a last name. If the user provides a value (e.g. types in a last name and then clicks OK or presses Enter), will attempt to locate the first record in the list with that last name. If a record is located, displays that record as the current record. If a record is not found, displays a message "Sorry, no record with last name of ___ was found", where ___ is the value supplied by the user.
If the user dismisses the input box (e.g. clicks Cancel or closes the dialog box), no further action is taken.
File | Open file menu choice Uses a JFileChooser to prompt the user to select a file. If the user selects a file, attempts to open that file. If opened, the existing list is cleared; all records from the file are read into the list.
When the end of file is reached, if the list has records, shows the first record. If the list is empty (e.g. file was empty), goes to Add mode.
File | Save file menu choice Uses a JFileChooser to prompt the user to select a file. If the user selects a file, attempts to open that file and write all records in the list to the file.
File | Exit menu choice Exits the program, same as clicking on the close button on the title bar.
Help | About menu choice Displays a message box describing the programmers.

Hints and tips
· Use the java.util.ArrayList to store the list of Friends in the application.
· Have an int attribute to track the record number that is currently being displayed.

Solution strategy:
1. Start by creating the Friend class.
2. Next, build up the FriendFrame by getting the appropriate layout of components.
3. Add the menu.
4. Get action listeners on everything that needs it, and code so each button or menu choice will display a little message saying "you pressed XXX".
5. Set up the frame so it can toggle between the different modes
6. Start adding simple functionality:
a. Get the Add button to work
b. Now make the navigation buttons work
c. Then work on the Update button, Find button and Delete button
d. Now work on saving the info to a file
e. Now work on reading info from a file
7. Refine code to have desired functionality
8. Test it out
General Assignment Instructions
The usual sort of thing applies for documenting, testing, and submitting, as outlined below.
Documenting:
· Follow the Programming Style Guidelines.
· Be sure that all files that have been modified or created for this assignment document both your and your partner's names and CST numbers.
Testing:
· Testing for the GUI should list the various tests that you tried, the expected result, and the actual result. Screen prints are not necessary. However, including a display of the "cheat board" may be useful to verify the program's behaviour.
· Include tests for handling files not found, files with no data, etc.
Submitting your assignment:
· Create a folder called A4CSTxxxCSTyyy.
· The xxx and yyy represent the digits in your CST number.
· Copy all of your source code, including the source code provided and your related documentation (test cases) into this folder.
· Using a program like PowerArchiver or WinZip, create a zip file named A4CSTxxxCSTyyy.zip that has the contents of this directory.
· The xxx and yyy represent the digits in your CST number.
· Email your zip file to Andrea

Share this post


Link to post

And there are seven other classes.

import java.io.FileNotFoundException;
import java.io.EOFException;
import java.io.IOException;
import java.io.FileInputStream;
import java.io.DataInputStream;
import java.io.FileOutputStream;
import java.io.DataOutputStream;

/**
 *
 * <p>Title: Friend Class</p>
 * <p>Description: A class that stores various information about a friend
 *
 * This was made for COSC190 Assginment 4.</p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: SIAST -- CST</p>
 * @author Andrew Bassett (CST101) & Jonathan Nicklin (CST238)
 * @version 1.0
 */
public class Friend implements Comparable
{
    private String lastName;
    private String firstName;
    private String street;
    private String city;
    private String province;
    private String postalCode;
    private String emailAddress;
    private String phoneNumber;
    private String note;

    /**
     * Constructor for the Friend object -- it takes in all of the information
     * for a friend. The names of the parameters are self-explanatory:
     *
     * @param lastName
     * @param firstName
     * @param street
     * @param city
     * @param province
     * @param postalCode
     * @param emailAddress
     * @param phoneNumber
     * @param note Miscellaneous notes about the person
     */
    public Friend(String lastName, String firstName, String street,
                  String city, String province, String postalCode,
                  String emailAddress, String phoneNumber, String note)
    {
        setLastName(lastName);
        setFirstName(firstName);
        setStreet(street);
        setCity(city);
        setProvince(province);
        setPostalCode(postalCode);
        setEmailAddress(emailAddress);
        setPhoneNumber(phoneNumber);
        setNote(note);
    }

    public Friend()
    {
    }

    public String getLastName()
    {
        return lastName;
    }

    public String getFirstName()
    {
        return firstName;
    }

    public String getStreet()
    {
        return street;
    }

    public String getCity()
    {
        return city;
    }

    public String getProvince()
    {
        return province;
    }

    public String getPostalCode()
    {
        return postalCode;
    }

    public String getEmailAddress()
    {
        return emailAddress;
    }

    public String getPhoneNumber()
    {
        return phoneNumber;
    }

    public String getNote()
    {
        return note;
    }

    public void setLastName(String lastName)
    {
        this.lastName = lastName;
    }

    public void setFirstName(String firstName)
    {
        this.firstName = firstName;
    }

    public void setStreet(String street)
    {
        this.street = street;
    }

    public void setCity(String city)
    {
        this.city = city;
    }

    public void setProvince(String province)
    {
        this.province = province;
    }

    public void setPostalCode(String postalCode)
    {
        this.postalCode = postalCode;
    }

    public void setEmailAddress(String emailAddress)
    {
        this.emailAddress = emailAddress;
    }

    public void setPhoneNumber(String phoneNumber)
    {
        this.phoneNumber = phoneNumber;
    }

    public void setNote(String note)
    {
        this.note = note;
    }

    /**
     *
     * @return the friend's full name in the format last name, first name.
     */
    public String getFullName()
    {
        return (lastName + ", " + firstName);
    }

    /**
     * Compares the lastName attributes of two Friend objects to see how they
     * compare to each other alphabetically.
     *
     * @param o The Object (must be Friend) being passed in to be compared
     *
     * @return 0 if they are the same, -1 if the passed in object is closer to
     * A alphabetically, 1 if the passed in object is closer to Z
     * alphabetically.
     *
     * @throws IllegalArgumentException if the argument being passed in is
     * not a Friend
     */
    public int compareTo(Object o) throws IllegalArgumentException
    {
        // Makes sure that a Friend object is being compared to a Friend
        if (!(o instanceof Friend))
        {
            throw new IllegalArgumentException(
                    "You must pass in a Friend object in order to compare."
                    );
        }

        // Converts the Object to a Friend and compares them based on their
        // last name.
        Friend f = (Friend)o;
        return lastName.compareToIgnoreCase(f.lastName );
    }

    /**
     * Compares two Friend objects to see if they're "equal."
     *
     * @param o The Object being passed in for comparing for equality
     * @return true if the lastName attributes are the same (ignores case)
     * @throws IllegalArgumentException if the argument being passed in is
     * not a Friend
     */
    public boolean equals(Object o) throws IllegalArgumentException
    {
        // Makes sure that a Friend object is being compared to a Friend
        if (!(o instanceof Friend))
        {
            throw new IllegalArgumentException(
                    "You must pass in a Friend object in order to equate."
                    );
        }

        // Converts the Object to a Friend and compares them based on their
        // last name.
        Friend f = (Friend)o;

        return f.lastName.compareToIgnoreCase(this.lastName) == 0;
    }

    /**
     *
     * @return a String containing all of the attribute information of the
     * Friend
     */
    public String toString()
    {
        StringBuffer buf = new StringBuffer(getClass().getName() );
        buf.append(": [lastName: ");
        buf.append(lastName);
        buf.append(", firstName: ");
        buf.append(firstName);
        buf.append(", street: ");
        buf.append(street);
        buf.append(", city: ");
        buf.append(city);
        buf.append(", province: ");
        buf.append(province);
        buf.append(", postalCode: ");
        buf.append(postalCode);
        buf.append(", emailAddress: ");
        buf.append(emailAddress);
        buf.append(", phoneNumber: ");
        buf.append(phoneNumber);
        buf.append(", note: ");
        buf.append(note);
        buf.append("]");

        return buf.toString();
    }

    /**
     * @return validity of e-mail address based on current object's attribute
     *
     * @throws NullPointerException if the email address is empty
     */
    public boolean isValidEmailAddress()
            throws NullPointerException
    {
        return isValidEmailAddress(emailAddress);
    }

    /**
     * Checks an e-mail address for validity (not if it's active, just if it
     * could be an e-mail address)
     *
     * The criteria is that it must have exactly one @ "at" sign in the String,
     * and at least one . period after the @ sign.
     *
     * @param emailAddress a String that may or may not contain an e-mail
     * address
     *
     * @return true if it is a valid e-mail address
     *
     * @throws NullPointerException if the email address is empty
     */
    public static boolean isValidEmailAddress(String emailAddress)
            throws NullPointerException
    {
        int atSignCounter = 0;
        boolean isValidDotSign = false;
        int i = 0;
        char character;

        if (emailAddress.length() == 0)
        {
            throw new NullPointerException(
                    "Cannot check an empty String for validity."
                    );
        }
        do
        {
            character = emailAddress.charAt(i);

            if (character == '@')
            {
                atSignCounter++;
            }
            if (character == '.' && atSignCounter > 0)
            {
                isValidDotSign = true;
            }

            i++;
        } while (i < emailAddress.length() );

        return (atSignCounter == 1 && isValidDotSign);
    }

    /**
     * Determines how a Friend object is written to a file -- it will simply
     * take each attribute of a Friend and write it to a file in binary
     *
     * @param dos a Data output stream object that represents a file that has
     * already been established
     *
     * @throws IOException if there is an error writing to the file
     */
    public void writeInfo(DataOutputStream dos)
            throws IOException, EOFException
    {
        try
        {
            dos.writeUTF(lastName);
            dos.writeUTF(firstName);
            dos.writeUTF(street);
            dos.writeUTF(city);
            dos.writeUTF(province);
            dos.writeUTF(postalCode);
            dos.writeUTF(emailAddress);
            dos.writeUTF(phoneNumber);
            dos.writeUTF(note);
        }
        catch (IOException e)
        {
            throw e;
        }
    }

    /**
     * Returns a new Friend object based on what is read in from a file
     *
     * @param dis an input stream from a file that has already been opened
     *
     * @return a new Friend object based on the first nine records of the
     * stream
     *
     * @throws IOException
     * @throws FileNotFoundException if the file cannot be read
     */
    public static Friend readInfo(DataInputStream dis)
            throws IOException, FileNotFoundException
    {
        try
        {
            return new Friend(dis.readUTF(), dis.readUTF(), dis.readUTF(),
                              dis.readUTF(), dis.readUTF(), dis.readUTF(),
                              dis.readUTF(), dis.readUTF(), dis.readUTF());
        }
        catch (FileNotFoundException e)
        {
            throw e;
        }
    }
}
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.filechooser.*;
import java.util.*;
import java.io.*;

/**
 *
 * <p>Title: Friend Frame GUI</p>
 * <p>Description: A graphical user interface that allows a user to open,
 * store, and manipulate information in the form of an address book
 *
 * This was made for COSC190 Assignment 4.</p>
 * <p>Copyright: Copyright (c) 2004</p>
 * <p>Company: SIAST -- CST</p>
 * @author Andrew Bassett (CST101) & Jonathan Nicklin (CST238)
 * @version 1.0
 */
public class FriendFrame extends JFrame implements ActionListener
{
    private ArrayList storage;
    private final int INITIAL_STORAGE_CAPACITY = 4;
    private int currentRecord;

    private final int ADD_MODE = 1;
    private final int UPDATE_MODE = 2;
    private final int VIEW_MODE = 3;
    private int mode;

    private final int DEFAULT_LABEL_COLOR = 0;
    private final int NUMBER_OF_FIELDS = 9;
    private final int LASTNAME_WIDTH = 20;
    private final int FIRSTNAME_WIDTH = 20;
    private final int STREET_WIDTH = 25;
    private final int ADDRESS_WIDTH = 25;
    private final int CITY_WIDTH = 20;
    private final int PROVINCE_WIDTH = 5;
    private final int POSTALCODE_WIDTH = 10;
    private final int EMAILADDRESS_WIDTH = 25;
    private final int PHONENUMBER_WIDTH = 10;
    private final int NOTE_WIDTH = 25;
    private final int NOTE_HEIGHT = 2;

    private JLabel lblLastName;
    private JLabel lblFirstName;
    private JLabel lblStreet;
    private JLabel lblCity;
    private JLabel lblProvince;
    private JLabel lblPostalCode;
    private JLabel lblEmailAddress;
    private JLabel lblPhoneNumber;
    private JLabel lblNote;

    private JLabel lblRecordInfo;

    private JTextField txtLastName;
    private JTextField txtFirstName;
    private JTextField txtStreet;
    private JTextField txtCity;
    private JTextField txtProvince;
    private JTextField txtPostalCode;
    private JTextField txtEmailAddress;
    private JTextField txtPhoneNumber;
    private JTextArea txtNote;
    //private JScrollPane txtNoteScrollPane;

    private JButton btnAdd;
    private JButton btnUpdate;
    private JButton btnDelete;
    private JButton btnSaveChanges;
    private JButton btnCancel;
    private JButton btnFirst;
    private JButton btnPrevious;
    private JButton btnLast;
    private JButton btnNext;
    private JButton btnFind;

    private JPanel pnlRecordInfoArea;
    private JPanel pnlTextFieldArea;
    private JPanel pnlButtonArea;

    private JMenu mnuFile;
    private JMenu mnuAction;
    private JMenu mnuNavigate;
    private JMenu mnuHelp;

    private JMenuItem miOpen;
    private JMenuItem miSave;
    private JMenuItem miExit;

    private JMenuItem miAdd;
    private JMenuItem miUpdate;
    private JMenuItem miDelete;
    private JMenuItem miSaveChanges;
    private JMenuItem miCancel;

    private JMenuItem miFirst;
    private JMenuItem miPrevious;
    private JMenuItem miNext;
    private JMenuItem miLast;
    private JMenuItem miFind;

    private JMenuItem miAbout;


    /**
     * Sets up the GUI when a new FriendFrame is constructed.
     */
    public FriendFrame()
    {
        super("Address Book");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        setupComponentsInitialization();
        setupLabelsText();
        setupTextFieldsSize();

        setupRecordInfoArea();
        setupTextFieldArea();
        setupButtonsText();
        setupButtonArea();

        setupButtonsListeners();
        setupMenusListeners();
        setupMenuBar();

        getContentPane().setLayout(new BorderLayout() );
        getContentPane().add(pnlRecordInfoArea, BorderLayout.NORTH);
        getContentPane().add(pnlTextFieldArea, BorderLayout.CENTER);
        getContentPane().add(pnlButtonArea, BorderLayout.SOUTH);

        storage = new ArrayList();
        currentRecord = 0;

        setMode(ADD_MODE);

        pack();
    }

    /**
     * Sets up the components of the GUI -- this allows them to be manipulated
     */
    private void setupComponentsInitialization()
    {
        setupLabelsInitialization();
        setupTextFieldsInitialization();
        setupButtonsAndMessageInitialization();
        setupMenusInitialization();
    }

    /**
     * Initializes the labels of the GUI so that they can be manipulated
     */
    private void setupLabelsInitialization()
    {
        lblLastName = new JLabel();
        lblFirstName = new JLabel();
        lblStreet = new JLabel();
        lblCity = new JLabel();
        lblProvince = new JLabel();
        lblPostalCode = new JLabel();
        lblEmailAddress = new JLabel();
        lblPhoneNumber = new JLabel();
        lblNote = new JLabel();
    }

    /**
     * Sets up the font of the labels
     */
    private void setupLabelsFont()
    {
        lblLastName.setForeground(new Color(DEFAULT_LABEL_COLOR) );
        lblFirstName.setForeground(new Color(DEFAULT_LABEL_COLOR) );
        lblStreet.setForeground(new Color(DEFAULT_LABEL_COLOR) );
        lblCity.setForeground(new Color(DEFAULT_LABEL_COLOR) );
        lblProvince.setForeground(new Color(DEFAULT_LABEL_COLOR) );
        lblPostalCode.setForeground(new Color(DEFAULT_LABEL_COLOR) );
        lblEmailAddress.setForeground(new Color(DEFAULT_LABEL_COLOR) );
        lblPhoneNumber.setForeground(new Color(DEFAULT_LABEL_COLOR) );
        lblNote.setForeground(new Color(DEFAULT_LABEL_COLOR) );
    }

    /**
     * Initializes the text fields of the GUI so that they can be manipulated
     */
    private void setupTextFieldsInitialization()
    {
        txtLastName = new JTextField();
        txtFirstName = new JTextField();
        txtStreet = new JTextField();
        txtCity = new JTextField();
        txtProvince = new JTextField();
        txtPostalCode = new JTextField();
        txtEmailAddress = new JTextField();
        txtPhoneNumber = new JTextField();
        txtNote = new JTextArea();
    }

    /**
     * Initializes the buttons of the GUI so that they can be manipulated
     */
    private void setupButtonsAndMessageInitialization()
    {
        btnAdd = new JButton();
        btnUpdate = new JButton();
        btnDelete = new JButton();
        btnSaveChanges = new JButton();
        btnCancel = new JButton();

        btnFirst = new JButton();
        btnPrevious = new JButton();
        btnNext = new JButton();
        btnLast = new JButton();
        btnFind = new JButton();
    }

    /**
     * Sets up the menu bars (File, Help, etc...) so that they can be
     * manipulated
     */
    private void setupMenusInitialization()
    {
        mnuFile = new JMenu();
        mnuAction = new JMenu();
        mnuNavigate = new JMenu();
        mnuHelp = new JMenu();

        setupFileMenuInitialization();
        setupActionMenuInitialization();
        setupNavigateMenuInitialization();
        setupHelpMenuInitialization();
    }

    /**
     * Sets up the items in the File menu so that they can be manipulated
     */
    private void setupFileMenuInitialization()
    {
        miOpen = new JMenuItem("Open file");
        miSave = new JMenuItem("Save file");
        miExit = new JMenuItem("Exit");
    }

    /**
     * Sets up the items in the Action menu so that they can be manipulated
     */
    private void setupActionMenuInitialization()
    {
        miAdd = new JMenuItem("Add");
        miUpdate = new JMenuItem("Update");
        miDelete = new JMenuItem("Delete");
        miSaveChanges = new JMenuItem("Save changes");
        miCancel = new JMenuItem("Cancel");
    }

    /**
     * Sets up the items in the Navigate menu so that they can be manipulated
     */
    private void setupNavigateMenuInitialization()
    {
        miFirst = new JMenuItem("First");
        miPrevious = new JMenuItem("Previous");
        miNext = new JMenuItem("Next");
        miLast = new JMenuItem("Last");
        miFind = new JMenuItem("Find");
    }

    /**
     * Sets up the item in the Help menu so that it can be manipulated
     */
    private void setupHelpMenuInitialization()
    {
        miAbout = new JMenuItem("About");
    }

    /**
     * Formats the JLabel components by adding text to them
     */
    private void setupLabelsText()
    {
        lblLastName.setText("Last name:");
        lblFirstName.setText("First name:");
        lblStreet.setText("Street:");
        lblCity.setText("City:");
        lblProvince.setText("Province:");
        lblPostalCode.setText("Postal code:");
        lblEmailAddress.setText("Email address:");
        lblPhoneNumber.setText("Phone number:");
        lblNote.setText("Notes:");
    }

    /**
     * Formats the JTextField components by setting their widths and heights
     *
     * This also formats the "Notes:" section of the text area by setting its
     * wrap style
     */
    private void setupTextFieldsSize()
    {
        txtLastName.setColumns(LASTNAME_WIDTH);
        txtFirstName.setColumns(FIRSTNAME_WIDTH);
        txtStreet.setColumns(STREET_WIDTH);
        txtCity.setColumns(CITY_WIDTH);
        txtProvince.setColumns(PROVINCE_WIDTH);
        txtPostalCode.setColumns(POSTALCODE_WIDTH);
        txtEmailAddress.setColumns(EMAILADDRESS_WIDTH);
        txtPhoneNumber.setColumns(PHONENUMBER_WIDTH);

        txtNote.setColumns(NOTE_WIDTH);
        txtNote.setRows(2);
        txtNote.setLineWrap(true);
        txtNote.setWrapStyleWord(true);
    }

    /**
     * Sets up the portion of the GUI that displays important information on the
     * record that is currently being displayed
     *
     */
    private void setupRecordInfoArea()
    {
        JPanel result = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5) );
        lblRecordInfo = new JLabel();

        result.add(lblRecordInfo);
        lblRecordInfo.setForeground(new Color(0, 0, 191) );
        lblRecordInfo.setFont(new Font("Arial", Font.BOLD, 16) );

        pnlRecordInfoArea = result;
    }

    /**
     * Sets up the text field portion of the GUI by adding the labels and the
     * text boxes
     *
     */
    private void setupTextFieldArea()
    {
        JPanel result = new JPanel(new GridLayout(NUMBER_OF_FIELDS, 1) );

        result.add(setupLastNameArea() );
        result.add(setupFirstNameArea() );
        result.add(setupStreetArea() );
        result.add(setupCityArea() );
        result.add(setupProvinceArea() );
        result.add(setupPostalCodeArea() );
        result.add(setupEmailAddressArea() );
        result.add(setupPhoneNumberArea() );
        result.add(setupNoteArea() );

        pnlTextFieldArea = result;
    }

    /**
     * Sets up the button area of the GUI by adding the two rows that the
     * buttons belong to.
     *
     */
    private void setupButtonArea()
    {
        JPanel result = new JPanel(new GridLayout(2, 1) );

        result.add(setupUpperButtonRow() );
        result.add(setupLowerButtonRow() );

        pnlButtonArea = result;
    }

    /**
     * Sets up the button components of the GUI by putting text on them
     */
    private void setupButtonsText()
    {
        btnAdd.setText("Add");
        btnUpdate.setText("Update");
        btnDelete.setText("Delete");
        btnSaveChanges.setText("Save");
        btnCancel.setText("Cancel");

        btnFirst.setText("<< First");
        btnPrevious.setText("< Previous");
        btnNext.setText("Next >");
        btnLast.setText("Last >>");
        btnFind.setText("Find");
    }

    /**
     * Sets up the buttons in the GUI so that they can cause events
     */
    private void setupButtonsListeners()
    {
        btnAdd.addActionListener(this);
        btnUpdate.addActionListener(this);
        btnDelete.addActionListener(this);
        btnSaveChanges.addActionListener(this);
        btnCancel.addActionListener(this);

        btnFirst.addActionListener(this);
        btnPrevious.addActionListener(this);
        btnNext.addActionListener(this);
        btnLast.addActionListener(this);
        btnFind.addActionListener(this);
    }

    /**
     * Sets up the menus is the GUI so that they can cause events
     */
    private void setupMenusListeners()
    {
        miOpen.addActionListener(this);
        miSave.addActionListener(this);
        miExit.addActionListener(this);

        miAdd.addActionListener(this);
        miUpdate.addActionListener(this);
        miDelete.addActionListener(this);
        miSaveChanges.addActionListener(this);
        miCancel.addActionListener(this);

        miFirst.addActionListener(this);
        miPrevious.addActionListener(this);
        miNext.addActionListener(this);
        miLast.addActionListener(this);
        miFind.addActionListener(this);

        miAbout.addActionListener(this);
    }

    /**
     * Sets up the menu bars (File, Help, etc...) for the GUI
     */
    private void setupMenuBar()
    {
        JMenuBar result = new JMenuBar();

        result.add(setupFileMenu() );
        result.add(setupActionMenu() );
        result.add(setupNavigateMenu() );
        result.add(setupHelpMenu() );

        setJMenuBar(result);
    }

    /**
     * Sets up the File menu by adding the necessary components
     *
     * @return a JMenu item containing the File menu
     */
    private JMenu setupFileMenu()
    {
        JMenu result = new JMenu("File");

        result.add(miOpen);
        result.add(miSave);
        result.addSeparator();
        result.add(miExit);

        return result;
    }

    /**
     * Sets up the Action menu by adding the necessary components
     *
     * @return a JMenu item containing the Action menu
     */
    private JMenu setupActionMenu()
    {
        JMenu result = new JMenu("Action");

        result.add(miAdd);
        result.add(miUpdate);
        result.add(miDelete);
        result.addSeparator();
        result.add(miSaveChanges);
        result.add(miCancel);

        return result;
    }

    /**
     * Sets up the Navigate menu by adding the necessary components
     *
     * @return a JMenu item containing the Navigate menu
     */
    private JMenu setupNavigateMenu()
    {
        JMenu result = new JMenu("Navigate");

        result.add(miFirst);
        result.add(miPrevious);
        result.add(miNext);
        result.add(miLast);
        result.addSeparator();
        result.add(miFind);

        return result;
    }

    /**
     * Sets up the Help menu by adding the necessary components
     *
     * @return a JMenu item containing the Help menu
     */
    private JMenu setupHelpMenu()
    {
        JMenu result = new JMenu("Help");

        result.add(miAbout);

        return result;
    }

    /**
     * Sets up the top row of buttons for the GUI
     *
     * @return a JPanel containing all of the components of the upper button row
     */
    private JPanel setupUpperButtonRow()
    {
        JPanel result = new JPanel(new FlowLayout(FlowLayout.CENTER) );

        result.add(btnAdd);
        result.add(btnUpdate);
        result.add(btnDelete);
        result.add(btnSaveChanges);
        result.add(btnCancel);

        return result;
    }

    /**
     * Sets up the bottom row of buttons for the GUI
     *
     * @return a JPanel containing all of the components of the lower button row
     */
    private JPanel setupLowerButtonRow()
    {
        JPanel result = new JPanel(new FlowLayout(FlowLayout.CENTER) );

        result.add(btnFirst);
        result.add(btnPrevious);
        result.add(btnNext);
        result.add(btnLast);
        result.add(btnFind);

        return result;
    }

    /**
     *
     * @return the section of the GUI where the user enters the last name info
     */
    private JPanel setupLastNameArea()
    {
        JPanel result = new JPanel(new FlowLayout(FlowLayout.LEFT) );
        result.add(lblLastName);
        result.add(txtLastName);

        return result;
    }

    /**
     *
     * @return the section of the GUI where the user enters the first name info
     */
    private JPanel setupFirstNameArea()
    {
        JPanel result = new JPanel(new FlowLayout(FlowLayout.LEFT) );
        result.add(lblFirstName);
        result.add(txtFirstName);

        return result;
    }

    /**
     *
     * @return the section of the GUI where the user enters the street info
     */
    private JPanel setupStreetArea()
    {
        JPanel result = new JPanel(new FlowLayout(FlowLayout.LEFT) );
        result.add(lblStreet);
        result.add(txtStreet);

        return result;
    }

    /**
     *
     * @return the section of the GUI where the user enters the city info
     */
    private JPanel setupCityArea()
    {
        JPanel result = new JPanel(new FlowLayout(FlowLayout.LEFT) );
        result.add(lblCity);
        result.add(txtCity);

        return result;
    }

    /**
     *
     * @return the section of the GUI where the user enters the province info
     */
    private JPanel setupProvinceArea()
    {
        JPanel result = new JPanel(new FlowLayout(FlowLayout.LEFT) );
        result.add(lblProvince);
        result.add(txtProvince);

        return result;
    }

    /**
     *
     * @return the section of the GUI where the user enters the postal code info
     */
    private JPanel setupPostalCodeArea()
    {
        JPanel result = new JPanel(new FlowLayout(FlowLayout.LEFT) );
        result.add(lblPostalCode);
        result.add(txtPostalCode);

        return result;
    }

    /**
     *
     * @return the section of the GUI where the user enters the email address
     * info
     */
    private JPanel setupEmailAddressArea()
    {
        JPanel result = new JPanel(new FlowLayout(FlowLayout.LEFT) );
        result.add(lblEmailAddress);
        result.add(txtEmailAddress);

        return result;
    }

    /**
     *
     * @return the section of the GUI where the user enters the phone number
     * info
     */
    private JPanel setupPhoneNumberArea()
    {
        JPanel result = new JPanel(new FlowLayout(FlowLayout.LEFT) );
        result.add(lblPhoneNumber);
        result.add(txtPhoneNumber);

        return result;
    }

    /**
     *
     * @return the section of the GUI where the user enters the email address
     * info
     */
    private JPanel setupNoteArea()
    {
        JPanel result = new JPanel(new FlowLayout(FlowLayout.LEFT) );
        JScrollPane pane = new JScrollPane(txtNote,
                JScrollPane.VERTICAL_SCROLLBAR_NEVER,
                JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

        result.add(lblNote);
        result.add(pane);

        return result;
    }

    /**
     * Sets the mode of the application -- this can be Add mode, Update mode,
     * or View mode.
     *
     * @param mode
     *
     *   Add mode -- to add a new record
     *  	- All text fields are enabled
     *      - Save button and Action | Save changes menu choice are enabled
     *      - If there are addresses already stored in the list, the Cancel button
     *        and Action | Cancel menu choice are enabled. However, if there are
     *        no records in the list, the Cancel button is disabled.
     *      - All other buttons are disabled.
     *      - All other menu choices under Action and Navigate are disabled.
     *
     *   Update mode -- to update the current record
     *      - All text fields are enabled
     *      - Save button and Action | Save changes menu choice are enabled
     *      - Cancel button and Action | Cancel menu choice are enabled
     *      - All other buttons are disabled
     *      - All other menu choices under Action and Navigate are disabled
     *
     *   View mode
     *      - All text fields are disabled
     *      - The Save and Cancel buttons and the Action | Save changes and Action | Cancel menu choices are disabled
     *      - All other buttons and menu choices are enabled
     *
     *      (Thanks to Andrea Grzesina for these comments)
     *
     * @throws IllegalArgumentException if the mode being passed in is not valid
     */
    private void setMode(int value)
            throws IllegalArgumentException
    {
        if (value < 1 || value > 3)
        {
            throw new IllegalArgumentException(
                    "Mode must be a valid integer representing either " +
                    "ADD_MODE, UPDATE_MODE, or VIEW_MODE"
                    );
        }
        else if (value == ADD_MODE)
        {
            if (currentRecord > 0)
            {
                currentRecord++;
            }

            displayNewRecord();
            setAllMenuItemsEnabled(false);
            setAllTextFieldsEnabled(true);
            setAllButtonsEnabled(false);

            btnSaveChanges.setEnabled(true);
            miSaveChanges.setEnabled(true);

            if (storage.size() > 0)
            {
                btnCancel.setEnabled(true);
                miCancel.setEnabled(true);
            }
            else
            {
                miOpen.setEnabled(true);
                miExit.setEnabled(true);
                miAbout.setEnabled(true);
            }
        }
        else if (value == UPDATE_MODE)
        {
            setAllMenuItemsEnabled(false);
            setAllTextFieldsEnabled(true);
            setAllButtonsEnabled(false);

            btnSaveChanges.setEnabled(true);
            miSaveChanges.setEnabled(true);
            btnCancel.setEnabled(true);
            miCancel.setEnabled(true);

            miExit.setEnabled(true);
            miAbout.setEnabled(true);
        }
        else if (value == VIEW_MODE)
        {
            setAllMenuItemsEnabled(true);
            setAllTextFieldsEnabled(false);
            setAllButtonsEnabled(true);

            btnSaveChanges.setEnabled(false);
            miSaveChanges.setEnabled(false);
            btnCancel.setEnabled(false);
            miCancel.setEnabled(false);
        }
        mode = value;
        updateRecordInfo();
    }

    /**
     * Sets all text fields in the GUI to the desired enabled/disabled status
     *
     * @param value true for enabled, false for disabled
     */
    private void setAllTextFieldsEnabled(boolean value)
    {
        txtLastName.setEnabled(value);
        txtFirstName.setEnabled(value);
        txtStreet.setEnabled(value);
        txtCity.setEnabled(value);
        txtProvince.setEnabled(value);
        txtPostalCode.setEnabled(value);
        txtEmailAddress.setEnabled(value);
        txtPhoneNumber.setEnabled(value);
        txtNote.setEnabled(value);
    }

    /**
     * Sets oll buttons in the GUI to the desired enabled/disabled status
     *
     * @param value true for enabled, false for disabled
     */
    private void setAllButtonsEnabled(boolean value)
    {
        btnAdd.setEnabled(value);
        btnUpdate.setEnabled(value);
        btnDelete.setEnabled(value);
        btnSaveChanges.setEnabled(value);
        btnCancel.setEnabled(value);
        btnFirst.setEnabled(value);
        btnPrevious.setEnabled(value);
        btnNext.setEnabled(value);
        btnLast.setEnabled(value);
        btnFind.setEnabled(value);
    }

    /**
     * Sets all menu items in the GUI to the desired status
     *
     * @param value true for enabled, false for disabled
     */
    private void setAllMenuItemsEnabled(boolean value)
    {
        miOpen.setEnabled(value);
        miSave.setEnabled(value);
        miExit.setEnabled(value);

        miAdd.setEnabled(value);
        miUpdate.setEnabled(value);
        miDelete.setEnabled(value);
        miSaveChanges.setEnabled(value);
        miCancel.setEnabled(value);

        miFirst.setEnabled(value);
        miPrevious.setEnabled(value);
        miNext.setEnabled(value);
        miLast.setEnabled(value);
        miFind.setEnabled(value);

        miAbout.setEnabled(value);
    }

    /**
     * Carries out the actions for when the user chooses to open a record
     */
    private void performOpen()
    {
        JFileChooser fc = new JFileChooser();
        int returnVal = fc.showOpenDialog(this);

        if (returnVal == JFileChooser.APPROVE_OPTION)
        {
            try
            {
                DataInputStream dis = new DataInputStream(
                        new FileInputStream(fc.getSelectedFile() ) );

                storage.clear();

                while (dis.available() > 0)
                {
                    storage.add(Friend.readInfo(dis) );
                }
                dis.close();

                if (storage.size() > 0)
                {
                    setMode(VIEW_MODE);
                }
                else
                {
                    setMode(ADD_MODE);
                }

                displayRecord(0);
            }
            catch (IOException e)
            {
                JOptionPane.showMessageDialog(this,
                        "Cannot open specified file.",
                        "Error",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    }

    /**
     * Carries out the actions for when the user chooses to save a record to
     * a file
     */
    private void performSave()
    {
        JFileChooser fc = new JFileChooser();
        int returnVal = fc.showSaveDialog(this);

        if (returnVal == JFileChooser.APPROVE_OPTION)
        {
            try
            {
                DataOutputStream dos = new DataOutputStream(
                        new FileOutputStream(fc.getSelectedFile() ) );

                for (int i = 0; i < storage.size(); i++)
                {
                    Friend f = (Friend)storage.get(i);
                    f.writeInfo(dos);
                }

            }
            catch (IOException e)
            {
                e.printStackTrace();
                JOptionPane.showMessageDialog(this,
                        "Cannot save to file. Verify that there is enough\n" +
                        "free disk space on the specified volume and that\n" +
                        "you have sufficient rights to save the file.",
                        "Error",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    }

    /**
     * Carries out the actions for when the user chooses to exit
     */
    private void performExit()
    {
        System.exit(0);
    }

    /**
     * Carries out the actions for when the user chooses to add a record
     */
    private void performAdd()
    {
        setMode(ADD_MODE);
    }

    /**
     * Carries out the actions for when the user chooses to update a record
     */
    private void performUpdate()
    {
        setMode(UPDATE_MODE);
    }

    /**
     * Carries out the actions for when the user chooses to add a record
     */
    private void performDelete()
    {
        boolean onlyRecord = false;
        boolean lastRecord = false;

        if (storage.size() == 1)
        {
            onlyRecord = true;
        }
        if (currentRecord == storage.size() - 1)
        {
            lastRecord = true;
        }

        storage.remove(currentRecord);

        if (onlyRecord)
        {
            setMode(ADD_MODE);
            displayNewRecord();
        }
        else if (lastRecord)
        {
            setMode(VIEW_MODE);
            displayRecord(--currentRecord);
        }
        else
        {
            setMode(VIEW_MODE);
            displayRecord(currentRecord);
        }
    }

    /**
     * Carries out the actions for when the user chooses to save changes
     */
    private void performSaveChanges()
    {
        Friend f = newFriend();

        try
        {
            if (!f.isValidEmailAddress() )
            {
                invalidEmailError();
            }
            else if (mode == ADD_MODE)
            {
                currentRecord = storage.size();
                storage.add(currentRecord, f);
                displayRecord(currentRecord);
                setMode(VIEW_MODE);
            }
            else if (mode == UPDATE_MODE)
            {
                storage.set(currentRecord, f);
                setMode(VIEW_MODE);
            }
        }
        catch (NullPointerException e)
        {
            invalidEmailError();
        }
    }

    /**
     * Carries out the actions for when the user chooses to cancel
     */
    private void performCancel()
    {
        if (mode == ADD_MODE)
        {
            setMode(VIEW_MODE);

            if (storage.size() == 0)
            {
                displayNewRecord();
            }
            else
            {
                displayRecord(currentRecord);
            }
        }
        else if (mode == UPDATE_MODE)
        {
            setMode(VIEW_MODE);
            displayRecord(currentRecord);
        }
    }

    /**
     * Carries out the actions for when the user chooses to go to the first
     * record
     */
    private void performFirst()
    {
        if (storage.size() == 0)
        {
            emptyListError();
        }
        else
        {
            displayRecord(currentRecord = 0);
        }
    }

    /**
     * Carries out the actions for when the user chooses to go to the previous
     * record
     */
    private void performPrevious()
    {
        if (storage.size() == 0)
        {
            emptyListError();
        }
        else if (currentRecord - 1 < 0)
        {
            JOptionPane.showMessageDialog(this, "You are at the first record.",
                    "Navigation Error", JOptionPane.ERROR_MESSAGE);
        }
        else
        {
            displayRecord(--currentRecord);
        }
    }

    /**
     * Carries out the actions for when the user chooses to go to the next
     * record
     */
    private void performNext()
    {
        if (storage.size() == 0)
        {
            emptyListError();
        }
        else if (currentRecord >= storage.size() - 1)
        {
            JOptionPane.showMessageDialog(this, "You are at the last record.",
                    "Navigation Error", JOptionPane.ERROR_MESSAGE);
        }
        else
        {
            displayRecord(++currentRecord);
        }
    }

    /**
     * Carries out the actions for when the user chooses to go to the last
     * record
     */
    private void performLast()
    {
        if (storage.size() == 0)
        {
            emptyListError();
        }
        else
        {
            displayRecord(currentRecord = storage.size() - 1);
        }
    }

    /**
     * Carries out the actions for when the user chooses to find a record
     *
     * If the user enters a name to search, it will search the entire collection
     * of last names. If none is found, a message dialog will display
     * indicating that no match could be found.
     */
    private void performFind()
    {
        int i = -1;
        boolean matchFound = false;
        String search = JOptionPane.showInputDialog(this,
                "Enter the last name that you want to find:",
                "Search", JOptionPane.OK_CANCEL_OPTION);

        while (i < storage.size() - 1 && !matchFound && search != null)
        {
            i++;
            String currentLastName = ((Friend)storage.get(i)).getLastName();

            if (search.equalsIgnoreCase(currentLastName) )
            {
                matchFound = true;
            }
        }

        if (matchFound)
        {
            currentRecord = i;
            displayRecord(currentRecord);
        }
        else if (search != null)
        {
            JOptionPane.showMessageDialog(this,
                    "Sorry, no record with last name of " + search +
                    " was found.", "Search", JOptionPane.PLAIN_MESSAGE);
        }
    }

    /**
     * Carries out the actions for when the user chooses to see information
     * about the Address Book
     */
    private void performAbout()
    {
        JOptionPane.showMessageDialog(this, "Address book created by\n" +
                                      "    Andrew Bassett (CST101)\n" +
                                      "    Jonathan Nicklin (CST238)",
                                      "About",
                                      JOptionPane.INFORMATION_MESSAGE);
    }

    /**
     * Carries out the appropriate action for when the user attempts to browse
     * while there are no records in the list
     */
    private void emptyListError()
    {
        JOptionPane.showMessageDialog(null,
                    "There are no records in the list to browse.",
                    "No Records",
                    JOptionPane.ERROR_MESSAGE);
    }

    /**
     * Carries out the appropriate action for when the user enters an
     * invalid email address
     */
    private void invalidEmailError()
    {
        JOptionPane.showMessageDialog(this,
                    "Email address is not valid. Please re-enter " +
                    "the email address.",
                    "Error",
                    JOptionPane.ERROR_MESSAGE);
    }

    /**
     * Loads the information from the desired record into
     * the text boxes
     */
    private void displayRecord(int record)
    {
        Friend f = (Friend)storage.get(record);

        txtLastName.setText(f.getLastName() );
        txtFirstName.setText(f.getFirstName() );
        txtStreet.setText(f.getStreet() );
        txtCity.setText(f.getCity() );
        txtProvince.setText(f.getProvince() );
        txtPostalCode.setText(f.getPostalCode() );
        txtEmailAddress.setText(f.getEmailAddress() );
        txtPhoneNumber.setText(f.getPhoneNumber() );
        txtNote.setText(f.getNote() );

        updateRecordInfo();
    }

    /**
     * Clears the text boxes in the address book so that the user can enter new
     * data
     */
    private void displayNewRecord()
    {
        txtLastName.setText(null);
        txtFirstName.setText(null);
        txtStreet.setText(null);
        txtCity.setText(null);
        txtProvince.setText(null);
        txtPostalCode.setText(null);
        txtEmailAddress.setText(null);
        txtPhoneNumber.setText(null);
        txtNote.setText(null);
    }

    /**
     * Creates a new Friend object based on the items currently entered in the
     * text boxes
     *
     * @return a new Friend object
     */
    private Friend newFriend()
    {
        return new Friend(
                txtLastName.getText(), txtFirstName.getText(),
                txtStreet.getText(), txtCity.getText(),
                txtProvince.getText(), txtPostalCode.getText(),
                txtEmailAddress.getText(), txtPhoneNumber.getText(),
                txtNote.getText()
                );
    }

    /**
     * Updates the record information label near the top of the GUI
     */
    private void updateRecordInfo()
    {
        if (mode == VIEW_MODE)
        {
            lblRecordInfo.setText("Viewing record " + (currentRecord + 1) +
                                  " of " + storage.size() );
        }
        else if (mode == ADD_MODE)
        {
            lblRecordInfo.setText("Creating new record at position " +
                                  (storage.size() + 1) );
        }
        else if (mode == UPDATE_MODE)
        {
            lblRecordInfo.setText("Updating record " + (currentRecord + 1) +
                                  " of " + storage.size() );
        }
    }

    /**
     * Handles all of the events that the GUI may encounter, such as a button
     * click, and deals with them appropriately
     *
     * @param ae an event that is taking place
     *
     * @throws IOException if a call to the performSave() function is
     * unsuccessful
     */
    public void actionPerformed(ActionEvent ae)
    {
        Object src = ae.getSource();
        String command = ae.getActionCommand();

        if (src instanceof JButton)
        {
            if (btnAdd.getText().equals(command) )
                performAdd();
            else if (btnUpdate.getText().equals(command) )
                performUpdate();
            else if (btnDelete.getText().equals(command) )
                performDelete();
            else if (btnSaveChanges.getText().equals(command) )
                performSaveChanges();
            else if (btnCancel.getText().equals(command) )
                performCancel();
            else if (btnFirst.getText().equals(command) )
                performFirst();
            else if (btnPrevious.getText().equals(command) )
                performPrevious();
            else if (btnNext.getText().equals(command) )
                performNext();
            else if (btnLast.getText().equals(command) )
                performLast();
            else if (btnFind.getText().equals(command) )
                performFind();
        }
        else if (src instanceof JMenuItem)
        {
            if (miOpen.getText().equals(command) )
                performOpen();
            else if (miSave.getText().equals(command) )
                performSave();
            else if (miExit.getText().equals(command) )
                performExit();
            else if (miAdd.getText().equals(command) )
                performAdd();
            else if (miUpdate.getText().equals(command) )
                performUpdate();
            else if (miDelete.getText().equals(command) )
                performDelete();
            else if (miSaveChanges.getText().equals(command) )
                performSaveChanges();
            else if (miCancel.getText().equals(command) )
                performCancel();
            else if (miFirst.getText().equals(command) )
                performFirst();
            else if (miPrevious.getText().equals(command) )
                performPrevious();
            else if (miNext.getText().equals(command) )
                performNext();
            else if (miLast.getText().equals(command) )
                performLast();
            else if (miFind.getText().equals(command) )
                performFind();
            else if (miAbout.getText().equals(command) )
                performAbout();
        }
    }

    /**
     * The main method that executes the program
     *
     * @param args
     */
    public static void main(String[] args)
    {
        FriendFrame ff = new FriendFrame();
        ff.setVisible(true);
    }
}

Share this post


Link to post

Indeed a very heavy assignment. Nothing too difficult or tricky in this, just lots and lots of code to write. I can understand why it takes so much time. In the end, however, you most likely emerge an expert in GUIs (and I/O streams).

The only thing that seems strange is the "solution strategy". That's too much spoon-feeding, I reckon. Overall, a fair assignment, but indeed way too long for any type of college/university class. Our assignments were rather short (sometimes very short). This work could very well be one of the final projects, if done with care.

How are your assignments graded and where are points usually taken off?

Share this post


Link to post

Points are taken off wherever and whenever they can find anything imperfect. The only exception to this is maybe spelling mistakes in comments and indentation strategies.

Share this post


Link to post
AndrewB said:

Points are taken off wherever and whenever they can find anything imperfect. The only exception to this is maybe spelling mistakes in comments and indentation strategies.


What would be considered imperfect? An ugly font on a button? Improper layout (I did notice the strict layout demands in the assignment)? Unconventionl naming of methods and variables?

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×