You are on page 1of 75

Example:

User Interface

Because this is to be a "standard GUI" style application, some attention needs to be


given to the user interface at this point. A user interface like the following might be
adopted. Not shown in the screen shot is a File menu with New, Open, Close, Save,
Save As ..., Print, and Quit options. For the "Edit" and "Delete" buttons, the user
must first select a person in the scrolling list of names, and then can click the
appropriate button to edit/delete that person.
Use Cases for a Simple Address Book

In the following, use cases are listed in the natural order that a user would think of
them. In the actual File menu, items that correspond to the various use cases will be
listed in the traditional order, which is slightly different.

Flows of Events for Individual Use Cases

Add a Person Use Case

The Add a Person use case is initiated when the user clicks the "Add" button in the
main window. A dialog box appears, with title "New Person", containing fields for the
user to fill in the new person's first and last names and other information. The box can
be dismissed by clicking either "OK" or "Cancel". If the "OK" button is clicked, a
new person is added to the end of the address book, and the person's name is added to
the end of the list of names in the main window. If the "Cancel" button is clicked, no
changes are made either to the address book or to the main window.

[ Sequence Diagram ]

Edit a Person Use Case

The Edit a Person use case is initiated when the user either highlights a name in the
list of names in the main window and then clicks the "Edit" button, or the user double-
clicks a name. In either case, a dialog box, with title "Edit person's name", appears
containing current information about the person selected, (except the person's name,
which appears only in the title). The user can then edit the individual fields. The box
can be dismissed by clicking either "OK" or "Cancel". If the "OK" button is clicked,
the entry in the address book for the selected person is updated to reflect any changes
made by the user. If the "Cancel" button is clicked, no changes are made to the
address book.

[ Sequence Diagram ]

Delete a Person Use Case

The Delete a Person use case is initiated when the user highlights a name in the list of
names in the main window and then clicks the "Delete" button. A dialog box appears,
asking the user to confirm deleting this particular individual. The box can be
dismissed by clicking either "OK" or "Cancel". If the "OK" button is clicked, the entry
in the address book for the selected person is deleted, and the person's name is deleted
from the list of names in the main window. If the "Cancel" button is clicked, no
changes are made either to the address book or to the main window.

[ Sequence Diagram ]

Sort Entries by Name Use Case

The Sort Entries by Name use case is initiated when the user clicks the Sort by Name
button in the main window. The entries in the address book are sorted alphabetically
by name, and the list in the main window is updated to reflect this order as well.
[ Sequence Diagram ]

Sort Entries by ZIP Use Case

The Sort Entries by ZIP use case is initiated when the user clicks the Sort by ZIP
button in the main window. The entries in the address book are sorted by zip code,
and the list in the main window is updated to reflect this order as well.

[ Sequence Diagram ]

Print Entries Use Case

The Print Entries use case is initiated when the user chooses "Print" from the File
menu. A save file dialog is displayed, and the user is allowed to choose a file to print
the labels to. (If the user cancels the file dialog, the Print operation is canceled.) The
current contents of the address book are written out to the specified file (in their
current order) in "mailing label" format. No information maintained by the program is
changed.

[ Sequence Diagram ]

Create New Address Book Use Case

The Create a New Address Book use case is initiated when the user chooses "New"
from the File menu. If the current address book contents have been changed since the
last successful New, Open, Save, or Save As ... operation was done, the Offer to Save
Changes extension is executed. Unless the user cancels the operation, a new empty
address book is then created and replaces the current address book. This results in the
list of names in the main window being cleared, the current file becoming undefined,
and the title of the main window becomes "Untitled". (NOTE: These conditions will
also be in effect when the program initially starts up.)

[ Sequence Diagram ]
Open Existing Address Book Use Case

The Open Existing Address Book use case is initiated when the user chooses "Open"
from the File menu. If the current address book contents have been changed since the
last successful New, Open, Save, or Save As ... operation was done, the Offer to Save
Changes extension is executed. Unless the user cancels the operation, a load file
dialog is displayed and the user is allowed to choose a file to open. Once the user
chooses a file, the current address book is replaced by the result of reading in the
specified address book. This results in the list of names in the main window being
replaced by the names in the address book that was read, the file that was opened
becoming the current file, and its name being displayed as the title of the main
window. (If the user cancels the file dialog, or attempting to read the file results in an
error, the current address book is left unchanged. If the cancellation results from an
error reading the file, a dialog box is displayed warning the user of the error.)

[ Sequence Diagram ]

Save Address Book Use Case

The Save Address Book use case is initiated when the user chooses "Save" from the
File menu. (The Save option is grayed out unless changes have been made to the
address book since the last New, Open, Save, or Save As ... operation was done.) If
there is a current file, the current address book is saved to this file. (If attempting to
write the file results in an error, a dialog box is displayed warning the user of the
error.) If there is no current file, the Save Address Book As .. use case is done instead.
In all cases, the current address book and window list are left unchanged.

[ Sequence Diagram ]

Save Address Book As ... Use Case

The Save Address Book As ... use case is initiated when the user chooses "Save As ..."
from the File menu. (The Save As ... option is always available.) A save file dialog is
displayed and the user is allowed to choose the name of a file in which to save the
address book. (If the user cancels the file dialog, the Save As ... operation is
canceled.) The current address book is saved to the specified file, and the file to which
it was saved becomes the current file and its name is displayed as the title of the main
window. (If attempting to write the file results in an error, a dialog box is displayed
warning the user of the error, and the current file and main window title are
unchanged.) In all cases, the current address book and window list are left unchanged.

[ Sequence Diagram ]

Quit Program Use Case

The Quit Program use case is initiated when the user chooses "Quit" from the File
menu, or clicks the close box for the main window. In either case, if the current
address book contents have been changed since the last New, Open, Save, or
Save As ... operation was done, the Offer to Save Changes extension is executed.
Unless the user cancels the operation, the program is terminated.

[ Sequence Diagram ]

Offer to Save Changes Extension

The Offer to Save Changes extension is initiated from within the Create New Address
Book, Open Existing Address Book, or Quit program use cases, if the current address
book has been changed since the last successful New, Open, Save, or Save As ...
operation was done. A dialog box is displayed, informing the user that there are
unsaved changes, and asking the user whether to save changes, not save changes, or
cancel the operation. If the user chooses to save changes, the Save Address Book Use
Case is executed (which may result in executing the Save Address Book As ... Use
Case if there is no current file). If the user chooses not to save changes, the original
operation is simply resumed. If the user chooses to cancel (or cancels the save file
dialog if one is needed), the original operation is canceled.

[ Sequence Diagram ]

Analysis

An initial reading of the use cases suggests that the following will be part of the
system.

 A single entity object representing the current address book that the program
is working with (AddressBook).
 An arbitrary number of entity objects, each representing one of the people
that is in the current address book (Person).
 A boundary object representing the interface between the address book
system and the human user (AddressBookGUI).
 A boundary object representing the interface between the address book
system and the file system on disk (FileSystem).
 A controller object that carries out the use cases in response to user gestures
on the GUI (AddressBookController). (For a problem of this small size, a single
controller is sufficient.)

The various use cases work with these objects, as follows:

 The Add a Person Use Case involves getting the new information from the
user, and then telling the AddressBook object to add a new person with this
information to its collection
 The Edit a Person Use Case involves displaying the current information about
the desired person (obtained from the AddressBook), then allowing the user to
enter new information for the various fields, then telling the AddressBook
object to make the changes.
 The Delete a Person Use Case involves asking the user to confirm deletion, and
then telling the AddressBook object to remove this person from its collection.
 The Sort Entries by Name Use Case involves telling the AddressBook object to
rearrange its collection in order of name.
 The Sort Entries by ZIP Use Case involves telling the AddressBook object to
rearrange its collection in order of ZIP.
 The Create New Address Book Use Case involves creating a new AddressBook
object.
 The Open Existing Address Book Use Case involves getting a file specification
from the user, and then telling the FileSystem object to read in an AddressBook
object from this file.
 The Save Address Book Use Case involves determining whether or not the
current AddressBook object has a file it was last read from / saved to; if so,
telling the FileSystem object to save the current AddressBook object to this
file. (If not, the Save Address Book As ... Use Case is done instead.)
 The Save Address Book As ... Use Case involves getting a file specification
from the user, and then telling the FileSystem object to save the current
AddressBook object to this file.
 The Print Address Book Use Case involves telling the AddressBook object to
print out its collection in order.
 (The Quit Program Use Case does not involve any of the other objects)
 (The Offer to Save Changes Extension may involve performing the Save
Address Book Use Case.)

CRC Cards for the Address Book Example

Responsibilities are assigned to the various classes based on the use of the model-
view-controller design pattern. The two entity classes (AddressBook and Person)
serve as the model. The GUI class (AddressBookGUI) serves as the view. The
controller class (AddressBookController) serves, of course, as the controller.

The view (AddressBookGUI) needs to be made an observer of the model


(specifically, AddressBook) so that it always reflects the current state of the model -
specifically, the list of names, the title, and its saved/needs to be saved status.

Using CRC cards to assign responsibilities to various classes for the tasks required by
the various use cases leads to the creation of the following cards.

 Class AddressBook
 Class AddressBookController
 Class AddressBookGUI
 Class FileSystem
 Class Person
Class AddressBook

The CRC Cards for class AddressBook are left as an exercise to the student

[ Links for this class ]

Class AddressBookController

The basic responsibility of an AddressBookController object is to carry out the


various use cases.

Responsibilities Collaborators

Allow the user to perform the Add a Person Use Case AddressBook

Allow the user to perform the Edit a Person Use Case AddressBook

Allow the user to perform the Delete a Person Use Case AddressBook

Allow the user to perform the Sort Entries by Name Use Case AddressBook

Allow the user to perform the Sort Entries by ZIP Use Case AddressBook

Allow the user to perform the Create New Address Book Use Case AddressBook

Allow the user to perform the Open Existing Address Book Use Case FileSystem

AddressBook
Allow the user to perform the Save Address Book Use Case
FileSystem

Allow the user to perform the Save Address Book As ... Use Case FileSystem

Allow the user to perform the Print Entries Use Case AddressBook

Perform the Offer to Save Changes Extension when needed by another


AddressBook
Use Case

[ Links for this class ]


Class AddressBookGUI

The basic responsibility of a GUI object is to allow interaction between the program
and the human user.

Responsibilities Collaborators

Keep track of the address book object it is displaying

Display a list of the names of persons in the current address book AddressBook

Display the title of the current address book - if any AddressBook

Maintain the state of the "Save" menu option - usable only when the
address book has been changed since the last time it was opened / AddressBook
saved.

Allow the user to request the performance of a use case AddressBookController

[ Links for this class ]

Class FileSystem

The basic responsibility of a FileSystem object is to manage interaction between the


program and the file system of the computer it is running on.

Responsibilities Collaborators

Read a stored address book from a file, given its file name AddressBook

Save an address book to a file, given its file name AddressBook

[ Links for this class ]

Class Person
The basic responsibility of a Person object is to maintain information about a single
individual.

Responsibilities Collaborators

Create a new object, given an individual's name, address, city, state, ZIP,
and phone

Furnish the individual's first name

Furnish the individual's last name

Furnish the individual's address

Furnish the individual's city

Furnish the individual's state

Furnish the individual's ZIP

Furnish the individual's phone number

Update the stored information (except the name) about an individual

[ Links for this class ]

Sequence Diagrams for the Address Book Example

Each of the use cases discovered in the analysis of the system will be realized by a
sequence of operations involving the various objects comprising the system.

 Sequence Diagram Realizing the Add a Person Use Case


 Sequence Diagram Realizing the Edit a Person Use Case
 Sequence Diagram Realizing the Delete a Person Use Case
 Sequence Diagram Realizing the Sort Entries by Name Use Case
 Sequence Diagram Realizing the Sort Entries by ZIP Use Case
 Sequence Diagram Realizing the Print Entries Use Case
 Sequence Diagram Realizing the Create New Address Book Use Case
 Sequence Diagram Realizing the Open Existing Address Book Use Case
 Sequence Diagram Realizing the Save Address Book Use Case
 Sequence Diagram Realizing the Save Address Book As ... Use Case
 Sequence Diagram Realizing the Offer to Save Changes Extension

Add a Person Use Case Sequence Diagram

Edit a Person Use Case Sequence Diagram


Delete a Person Use Case Sequence Diagram
Sort Entries By Name Use Case Sequence Diagram

Sort Entries By Zip Use Case Sequence Diagram


Print Entries Use Case Sequence Diagram

Create New Address Book Use Case Sequence Diagram


Open Existing Address Book Use Case Sequence Diagram
Save Address Book Use Case Sequence Diagram

Save Address Book As ... Use Case Sequence Diagram

The Sequence Diagram for the Save Address Book As ... Use Case is left as an
exercise to the student

Offer To Save Changes Extension Use Case


Class Diagram for the Address Book Example

Shown below is the class diagram for the Address Book Example. To prevent the
diagram from becoming overly large, only the name of each class is shown - the
attribute and behavior "compartments" are shown in the detailed design, but are
omitted here.

The diagram includes the classes discovered during analysis, plus some additional
classes discovered during design. (In a more significant system, the total number of
classes may be about five times as great as the number of classes uncovered during
analysis.)

 AddressBookApplication - main class for the application; responsible for


creating the FileSystem and GUI objects and starting up the application.
 MultiInputPane - a utility class for reading multiple values at a single time.
(Design not further documented, but javadoc is included.)
 Person.CompareByName - Comparator for comparing two Person objects by
name (used for sorting by name).
 Person.CompareByZip - Comparator for comparing two Person objects by zip
(used for sorting by name).

The following relationships hold between the objects:

 The main application object is responsible for creating a single file system
object and a single controller object.
 The file system object is responsible for saving and re-loading address books
 The controller object is responsible for creating a single GUI object.
 The controller object is responsible for initially creating an address book
object, but the GUI is henceforth responsible for keeping track of its current
address book - of which it only has one at any time.
 The GUI object and the address object are related by an observer-observable
relationship, so that changes to the address book content lead to
corresponding changes in the display
 The address book object is responsible for creating and keeping track of
person objects, of which there can be many in any given address book.
 A MultiInputPane object is used by the controller to allow the user to enter
multiple items of data about a person.
 A comparator object of the appropriate kind is used by the address book
object when sorting itself.

Click on a class icon for links to further information about it


Detailed Class Design for the Address Book Example

Given below is a "three compartment" design for the classes appearing in the class diagram. This
information was not included in that diagram due to size considerations; however, it could have
been - in which case this document would have been unnecessary.

 Class AddressBook
 Class AddressBookApplication
 Class AddressBookController
 Class AddressBookGUI
 Class FileSystem
 Class Person
 (No detailed design is given for Comparator class Person.CompareByName)
 (No detailed design is given for Comparator class Person.CompareByZip)
 (No detailed design is given for utility class MultiInputPane)
The detailed design of class AddressBookController is left as an exercise to the
student
Code for Simple Address Book Example

As noted in the introduction, the writing of much of the code for this problem is an
assignment in two closed labs and an open lab programming project in one of the
courses I teach. This page includes links to portions of the code that are not assigned
(and are, in fact, given to the students in the course.)

This page also provides access to Complete Javadoc Documentation for all of the
classes.

 AddressBookApplication
 AddressBookGUI
 MultiInputPane
 Comparator Classes - inner classes in class Person
 All Classes
AddressBook
AddressBookApplet
AddressBookApplication
AddressBookController
AddressBookGUI
FileSystem
MultiInputPane
Person
Person.CompareByName
Person.CompareByZip

Class AddressBook
java.lang.Object
java.util.Observable
AddressBook
All Implemented Interfaces:

java.io.Serializable

public class AddressBook

extends java.util.Observable

implements java.io.Serializable

An object of this class maintains the collection of Person objects that constitute an
address book

See Also:

Serialized Form

Constructor Summary

AddressBook()
Constructor - create a new, empty address book
Method Summary
void addPerson(java.lang.String firstName,
java.lang.String lastName, java.lang.String address,
java.lang.String city, java.lang.String state,
java.lang.String zip, java.lang.String phone)
Add a new Person to the collection

boolean getChangedSinceLastSave()

Find out whether this address book has been changed


since last open / save

java.io.File getFile()

Get the File this address book was most recently read
from or saved to

java.lang.String getFullNameOfPerson(int index)

Provide the full name of a person

int getNumberOfPersons()

Get the current size of the collection

java.lang.String[] getOtherPersonInformation(int index)

Provide the rest of the current information about a


person

java.lang.String getTitle()

Get the title of this address book - based on the most


recently used file

void printAll()

Print the collection of persons in order.

void removePerson(int index)

Remove a specific person from the collection


void setChangedSinceLastSave(boolean changedSinceLastSave)

Record a change in the saved status of this address book

void setFile(java.io.File file)

Set the File this address book was most recently read
from or saved to

void sortByName()

Sort the collection by name

void sortByZip()

Sort the collection by ZIP

void updatePerson(int index, java.lang.String address,


java.lang.String city, java.lang.String state,
java.lang.String zip, java.lang.String phone)
Update stored information about a person

Methods inherited from class java.util.Observable

addObserver, clearChanged, countObservers, deleteObserver, deleteObservers,


hasChanged, notifyObservers, notifyObservers, setChanged

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString,


wait, wait, wait

Constructor Detail

AddressBook
public AddressBook()
Constructor - create a new, empty address book

Method Detail

getNumberOfPersons
public int getNumberOfPersons()
Get the current size of the collection

Returns:

the number of persons in the collection

addPerson
public void addPerson(java.lang.String firstName,
java.lang.String lastName,
java.lang.String address,
java.lang.String city,
java.lang.String state,
java.lang.String zip,
java.lang.String phone)
Add a new Person to the collection

Parameters:

firstName - the person's first name

lastName - the person's last name

address - the person's address

city - the person's city

state - the person's state

zip - the person's zip

phone - the person's phone


getFullNameOfPerson
public java.lang.String getFullNameOfPerson(int index)
Provide the full name of a person

Parameters:

index - the position of the desired person

Returns:

the person's full name, in a form suitable for displaying or printing

getOtherPersonInformation
public java.lang.String[] getOtherPersonInformation(int index)
Provide the rest of the current information about a person

Parameters:

index - the position of the desired person

Returns:

an array of Strings, each containing one piece of stored information about this
person. The person's name is _not_ included, since this is not changeable.

updatePerson
public void updatePerson(int index,
java.lang.String address,
java.lang.String city,
java.lang.String state,
java.lang.String zip,
java.lang.String phone)
Update stored information about a person

Parameters:

index - the position of the desired person


address - the person's new address

city - the person's new city

state - the person's new state

zip - the person's new zip

phone - the person's new phone

removePerson
public void removePerson(int index)
Remove a specific person from the collection

Parameters:

index - the position of the desired person

sortByName
public void sortByName()
Sort the collection by name

sortByZip
public void sortByZip()
Sort the collection by ZIP

printAll
public void printAll()
Print the collection of persons in order.
getFile
public java.io.File getFile()
Get the File this address book was most recently read from or saved to

Returns:

the most recent File - if any - null if none

getTitle
public java.lang.String getTitle()
Get the title of this address book - based on the most recently used file

Returns:

the title of this address book - "Untitled" if none

setFile
public void setFile(java.io.File file)
Set the File this address book was most recently read from or saved to

Parameters:

file - the file just used to read or save this object

getChangedSinceLastSave
public boolean getChangedSinceLastSave()
Find out whether this address book has been changed since last open / save

Returns:

true if this address book has been changed since the last open / save; false if
not
setChangedSinceLastSave
public void setChangedSinceLastSave(boolean changedSinceLastSave)
Record a change in the saved status of this address book

Parameters:

changedSinceLastSave - the new status

Class AddressBookApplet
java.lang.Object
java.awt.Component
java.awt.Container
java.awt.Panel
java.applet.Applet
javax.swing.JApplet
AddressBookApplet
All Implemented Interfaces:

javax.accessibility.Accessible, java.awt.image.ImageObserver,
java.awt.MenuContainer, javax.swing.RootPaneContainer, java.io.Serializable

public class AddressBookApplet

extends javax.swing.JApplet

Applet version of address book application

See Also:

Serialized Form

Nested Class Summary


Nested classes inherited from class javax.swing.JApplet

javax.swing.JApplet.AccessibleJApplet

Nested classes inherited from class java.applet.Applet

java.applet.Applet.AccessibleApplet

Nested classes inherited from class java.awt.Panel

java.awt.Panel.AccessibleAWTPanel

Nested classes inherited from class java.awt.Container

java.awt.Container.AccessibleAWTContainer

Nested classes inherited from class java.awt.Component

java.awt.Component.AccessibleAWTComponent,
java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy

Field Summary

Fields inherited from class javax.swing.JApplet

accessibleContext, rootPane, rootPaneCheckingEnabled


Fields inherited from class java.awt.Component

BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT,


TOP_ALIGNMENT

Fields inherited from interface java.awt.image.ImageObserver

ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH

Constructor Summary

AddressBookApplet()

Method Summary
void init()

Initialization for the applet

Methods inherited from class javax.swing.JApplet

addImpl, createRootPane, getAccessibleContext, getContentPane, getGlassPane,


getJMenuBar, getLayeredPane, getRootPane, isRootPaneCheckingEnabled,
paramString, remove, setContentPane, setGlassPane, setJMenuBar,
setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update

Methods inherited from class java.applet.Applet

destroy, getAppletContext, getAppletInfo, getAudioClip, getAudioClip,


getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter,
getParameterInfo, isActive, newAudioClip, play, play, resize, resize,
setStub, showStatus, start, stop

Methods inherited from class java.awt.Panel

addNotify

Methods inherited from class java.awt.Container

add, add, add, add, add, addContainerListener, addPropertyChangeListener,


addPropertyChangeListener, applyComponentOrientation,
areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout,
findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent,
getComponentAt, getComponentAt, getComponentCount, getComponents,
getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy,
getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize,
getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot,
isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate,
minimumSize, paint, paintComponents, preferredSize, print, printComponents,
processContainerEvent, processEvent, remove, removeAll,
removeContainerListener, removeNotify, setFocusCycleRoot,
setFocusTraversalKeys, setFocusTraversalPolicy, setFont,
transferFocusBackward, transferFocusDownCycle, validate, validateTree

Methods inherited from class java.awt.Component

action, add, addComponentListener, addFocusListener,


addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener,
addKeyListener, addMouseListener, addMouseMotionListener,
addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents,
contains, contains, createImage, createImage, createVolatileImage,
createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable,
enableEvents, enableInputMethods, firePropertyChange, firePropertyChange,
firePropertyChange, getBackground, getBounds, getBounds, getColorModel,
getComponentListeners, getComponentOrientation, getCursor, getDropTarget,
getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled,
getFont, getFontMetrics, getForeground, getGraphics,
getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners,
getHierarchyListeners, getIgnoreRepaint, getInputContext,
getInputMethodListeners, getInputMethodRequests, getKeyListeners,
getLocation, getLocation, getLocationOnScreen, getMouseListeners,
getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer,
getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize,
getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent,
hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet,
isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner,
isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque,
isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location,
lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp,
move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll,
processComponentEvent, processFocusEvent, processHierarchyBoundsEvent,
processHierarchyEvent, processInputMethodEvent, processKeyEvent,
processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove,
removeComponentListener, removeFocusListener, removeHierarchyBoundsListener,
removeHierarchyListener, removeInputMethodListener, removeKeyListener,
removeMouseListener, removeMouseMotionListener, removeMouseWheelListener,
removePropertyChangeListener, removePropertyChangeListener, repaint, repaint,
repaint, repaint, requestFocus, requestFocus, requestFocusInWindow,
requestFocusInWindow, reshape, setBackground, setBounds, setBounds,
setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable,
setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale,
setLocation, setLocation, setName, setSize, setSize, setVisible, show, show,
size, toString, transferFocus, transferFocusUpCycle

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait,


wait

Constructor Detail

AddressBookApplet
public AddressBookApplet()

Method Detail
init
public void init()
Initialization for the applet

Class AddressBookApplication
java.lang.Object
AddressBookApplication

public class AddressBookApplication

extends java.lang.Object

Main class for the Address Book example

Constructor Summary

AddressBookApplication()

Method Summary
static void main(java.lang.String[] args)

Main method for program

static void quitApplication()

Terminate the application (unless cancelled by the user)

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString,


wait, wait, wait

Constructor Detail

AddressBookApplication
public AddressBookApplication()

Method Detail

main
public static void main(java.lang.String[] args)
Main method for program

quitApplication
public static void quitApplication()
Terminate the application (unless cancelled by the user)

Class AddressBookApplication
java.lang.Object
AddressBookApplication

public class AddressBookApplication

extends java.lang.Object

Main class for the Address Book example

Constructor Summary

AddressBookApplication()
Method Summary
static void main(java.lang.String[] args)

Main method for program

static void quitApplication()

Terminate the application (unless cancelled by the user)

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString,


wait, wait, wait

Constructor Detail

AddressBookApplication
public AddressBookApplication()

Method Detail

main
public static void main(java.lang.String[] args)
Main method for program

quitApplication
public static void quitApplication()
Terminate the application (unless cancelled by the user)

Class AddressBookController
java.lang.Object
AddressBookController

public class AddressBookController

extends java.lang.Object

An object of this class performs operations on the address book in response to user
gestures on the GUI

Constructor Summary

AddressBookController(FileSystem fileSystem)
Constructor

Method Summary
void doAdd(AddressBookGUI gui)

Do the Add a Person Use Case.

void doDelete(AddressBookGUI gui, int index)

Do the Delete a Person use case

void doEdit(AddressBookGUI gui, int index)

Do the Edit a Person use case

void doNew(AddressBookGUI gui)

Do the Create New Address Book Use Case


void doOfferSaveChanges(AddressBookGUI gui)

Do Offer to Save Changes extension.

void doOpen(AddressBookGUI gui)

Do the Open Existing Address Book Use Case

void doPrint(AddressBookGUI gui)

Do the Print Entries Use Case

void doSave(AddressBookGUI gui)

Do the Save Address Book Use Case.

void doSaveAs(AddressBookGUI gui)

Do the Save Address Book As use case

void doSortByName(AddressBookGUI gui)

Do the Sort Entries by Name Use Case

void doSortByZip(AddressBookGUI gui)

Do the Sort Entries by ZIP Use Case

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString,


wait, wait, wait

Constructor Detail

AddressBookController
public AddressBookController(FileSystem fileSystem)
Constructor
Parameters:

fileSystem - the object to use for interacting with the file system

Method Detail

doAdd
public void doAdd(AddressBookGUI gui)
Do the Add a Person Use Case.

Parameters:

gui - the gui that requested this operation

doEdit
public void doEdit(AddressBookGUI gui,
int index)
Do the Edit a Person use case

Parameters:

gui - the gui that requested this operation

index - the position of the desired person

doDelete
public void doDelete(AddressBookGUI gui,
int index)
Do the Delete a Person use case

Parameters:

gui - the gui that requested this operation

index - the position of the desired person


doSortByName
public void doSortByName(AddressBookGUI gui)
Do the Sort Entries by Name Use Case

Parameters:

gui - the gui that requested this operation

doSortByZip
public void doSortByZip(AddressBookGUI gui)
Do the Sort Entries by ZIP Use Case

Parameters:

gui - the gui that requested this operation

doPrint
public void doPrint(AddressBookGUI gui)
Do the Print Entries Use Case

Parameters:

gui - the gui that requested this operation

doNew
public void doNew(AddressBookGUI gui)
Do the Create New Address Book Use Case

Parameters:

gui - the gui that requested this operation


doOpen
public void doOpen(AddressBookGUI gui)
throws java.io.IOException,
java.lang.ClassCastException,
java.lang.ClassNotFoundException,
java.lang.InterruptedException,
java.lang.SecurityException
Do the Open Existing Address Book Use Case

Parameters:

gui - the gui that requested this operation

Throws:

java.io.IOException - if there is a problem reading the file

java.lang.ClassCastException - if the file does not contain an AddressBook

java.lang.ClassNotFoundException - if the file does not contain an


AddressBook, and the class it does contain is not found - this should never
happen

java.lang.InterruptedException - if the user cancels the operation

java.lang.SecurityException - if the security manager disallows the operation

doSave
public void doSave(AddressBookGUI gui)
throws java.io.IOException,
java.lang.InterruptedException,
java.lang.SecurityException
Do the Save Address Book Use Case. If there is no file for the current address
book, doSaveAs() will be done instead

Parameters:

gui - the gui that requested this operation


Throws:

java.io.IOException - if there is a problem writing the file

java.lang.InterruptedException - will be propagated if thrown by doSaveAs()

java.lang.SecurityException - will be propagated if thrown by doSaveAs()

doSaveAs
public void doSaveAs(AddressBookGUI gui)
throws java.io.IOException,
java.lang.InterruptedException,
java.lang.SecurityException
Do the Save Address Book As use case

Parameters:

gui - the gui that requested this operation

Throws:

java.io.IOException - if there is a problem writing the file

java.lang.InterruptedException - if the user cancels the operation

java.lang.SecurityException - if the security manager disallows the operation

doOfferSaveChanges
public void doOfferSaveChanges(AddressBookGUI gui)
throws java.lang.InterruptedException,
java.io.IOException,
java.lang.SecurityException
Do Offer to Save Changes extension. This method is called if the user initiates
a new, open, or quit operation, or tries to close the window, with unsaved
changes to the address book. The user is offered an opportunity to save those
changes before proceeding.

Parameters:
gui - the gui that requested this operation

Throws:

java.lang.InterruptedException - if the user cancels the operation

java.io.IOException - will be propagated if thrown by doSave()

java.lang.SecurityException - will be propagated if thrown by doSave()

Class AddressBookGUI
java.lang.Object
java.awt.Component
java.awt.Container
java.awt.Window
java.awt.Frame
javax.swing.JFrame
AddressBookGUI
All Implemented Interfaces:

javax.accessibility.Accessible, java.awt.image.ImageObserver,
java.awt.MenuContainer, java.util.Observer, javax.swing.RootPaneContainer,
java.io.Serializable, javax.swing.WindowConstants

public class AddressBookGUI

extends javax.swing.JFrame

implements java.util.Observer

An object of this class allows interaction between the program and the human user.

See Also:

Serialized Form

Nested Class Summary


Nested classes inherited from class javax.swing.JFrame

javax.swing.JFrame.AccessibleJFrame

Nested classes inherited from class java.awt.Frame

java.awt.Frame.AccessibleAWTFrame

Nested classes inherited from class java.awt.Window

java.awt.Window.AccessibleAWTWindow

Nested classes inherited from class java.awt.Container

java.awt.Container.AccessibleAWTContainer

Nested classes inherited from class java.awt.Component

java.awt.Component.AccessibleAWTComponent,
java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy

Field Summary

Fields inherited from class javax.swing.JFrame

accessibleContext, EXIT_ON_CLOSE, rootPane, rootPaneCheckingEnabled


Fields inherited from class java.awt.Frame

CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED,


MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR,
N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR,
SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR

Fields inherited from class java.awt.Component

BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT,


TOP_ALIGNMENT

Fields inherited from interface javax.swing.WindowConstants

DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE

Fields inherited from interface java.awt.image.ImageObserver

ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH

Constructor Summary

AddressBookGUI(AddressBookController controller, AddressBook addressBook)


Constructor

Method Summary
AddressBook
getAddressBook()
Accessor for the address book this GUI displays

void reportError(java.lang.String message)

Report an error to the user

void setAddressBook(AddressBook addressBook)

Mutator to change the address book this GUI displays

void update(java.util.Observable o, java.lang.Object arg)

Method required by the Observer interface - update the display


in response to any change in the address book

Methods inherited from class javax.swing.JFrame

addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane,


getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane,
getRootPane, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled,
paramString, processWindowEvent, remove, setContentPane,
setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane,
setJMenuBar, setLayeredPane, setLayout, setRootPane,
setRootPaneCheckingEnabled, update

Methods inherited from class java.awt.Frame

addNotify, finalize, getCursorType, getExtendedState, getFrames,


getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle,
isResizable, isUndecorated, remove, removeNotify, setCursor,
setExtendedState, setIconImage, setMaximizedBounds, setMenuBar, setResizable,
setState, setTitle, setUndecorated

Methods inherited from class java.awt.Window

addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener,


addWindowListener, addWindowStateListener, applyResourceBundle,
applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose,
getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor,
getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration,
getInputContext, getListeners, getLocale, getMostRecentFocusOwner,
getOwnedWindows, getOwner, getToolkit, getWarningString,
getWindowFocusListeners, getWindowListeners, getWindowStateListeners, hide,
isActive, isFocusableWindow, isFocusCycleRoot, isFocused, isShowing, pack,
postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent,
removeWindowFocusListener, removeWindowListener, removeWindowStateListener,
setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationRelativeTo,
show, toBack, toFront

Methods inherited from class java.awt.Container

add, add, add, add, add, addContainerListener, applyComponentOrientation,


areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout,
findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent,
getComponentAt, getComponentAt, getComponentCount, getComponents,
getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout,
getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate,
isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list,
list, locate, minimumSize, paint, paintComponents, preferredSize, print,
printComponents, processContainerEvent, remove, removeAll,
removeContainerListener, setFocusTraversalKeys, setFocusTraversalPolicy,
setFont, transferFocusBackward, transferFocusDownCycle, validate,
validateTree

Methods inherited from class java.awt.Component

action, add, addComponentListener, addFocusListener,


addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener,
addKeyListener, addMouseListener, addMouseMotionListener,
addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents,
contains, contains, createImage, createImage, createVolatileImage,
createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable,
enableEvents, enableInputMethods, firePropertyChange, firePropertyChange,
firePropertyChange, getBackground, getBounds, getBounds, getColorModel,
getComponentListeners, getComponentOrientation, getCursor, getDropTarget,
getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics,
getForeground, getGraphics, getHeight, getHierarchyBoundsListeners,
getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners,
getInputMethodRequests, getKeyListeners, getLocation, getLocation,
getLocationOnScreen, getMouseListeners, getMouseMotionListeners,
getMouseWheelListeners, getName, getParent, getPeer,
getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize,
getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus,
imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable,
isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable,
isFontSet, isForegroundSet, isLightweight, isOpaque, isValid, isVisible,
keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag,
mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll,
prepareImage, prepareImage, printAll, processComponentEvent,
processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent,
processInputMethodEvent, processKeyEvent, processMouseEvent,
processMouseMotionEvent, processMouseWheelEvent, removeComponentListener,
removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener,
removeInputMethodListener, removeKeyListener, removeMouseListener,
removeMouseMotionListener, removeMouseWheelListener,
removePropertyChangeListener, removePropertyChangeListener, repaint, repaint,
repaint, repaint, requestFocus, requestFocus, requestFocusInWindow,
requestFocusInWindow, reshape, resize, resize, setBackground, setBounds,
setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable,
setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale,
setLocation, setLocation, setName, setSize, setSize, setVisible, show, size,
toString, transferFocus, transferFocusUpCycle

Methods inherited from class java.lang.Object

clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait

Methods inherited from interface java.awt.MenuContainer

getFont, postEvent

Constructor Detail

AddressBookGUI
public AddressBookGUI(AddressBookController controller,
AddressBook addressBook)
Constructor
Parameters:

controller - the controller which performs operations in response to user


gestures on this GUI

addressBook - the AddressBook this GUI displays

Method Detail

getAddressBook
public AddressBook getAddressBook()
Accessor for the address book this GUI displays

Returns:

the current address book for this GUI

setAddressBook
public void setAddressBook(AddressBook addressBook)
Mutator to change the address book this GUI displays

Parameters:

addressBook - the new address book for this GUI

reportError
public void reportError(java.lang.String message)
Report an error to the user

Parameters:

message - the message to display


update
public void update(java.util.Observable o,
java.lang.Object arg)
Method required by the Observer interface - update the display in response to
any change in the address book

Specified by:

update in interface java.util.Observer

Class FileSystem
java.lang.Object
FileSystem

public class FileSystem

extends java.lang.Object

An object of this class manages interaction between the address book program and the
file system of the computer it is running on.

Constructor Summary

FileSystem()

Method Summary
AddressBook readFile(java.io.File file)

Read a stored file

void saveFile(AddressBook addressBook, java.io.File file)

Save an address book to a file


Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString,


wait, wait, wait

Constructor Detail

FileSystem
public FileSystem()

Method Detail

readFile
public AddressBook readFile(java.io.File file)
throws java.io.IOException,
java.lang.ClassCastException,
java.lang.ClassNotFoundException
Read a stored file

Parameters:

file - the file specification for the file to read

Returns:

the AddressBook object stored in the file

Throws:

java.io.IOException - if there is a problem reading the file

java.lang.ClassCastException - if the file does not contain an AddressBook


java.lang.ClassNotFoundException - if the file does not contain an
AddressBook, and the class it does contain is not found - this should never
happen

saveFile
public void saveFile(AddressBook addressBook,
java.io.File file)
throws java.io.IOException
Save an address book to a file

Parameters:

addressBook - the AddressBook to save

file - the file specification for the file to create

Throws:

java.io.IOException - if there is a problem writing the file

Class MultiInputPane
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JOptionPane
MultiInputPane
All Implemented Interfaces:

javax.accessibility.Accessible, java.awt.image.ImageObserver,
java.awt.MenuContainer, java.io.Serializable

public class MultiInputPane

extends javax.swing.JOptionPane

This is a utility class for displaying a dialog that asks for multiple values. Based on
ideas in Wu's javabook.MultiInputBox class and on ideas in javax.swing.JOptionPane
See Also:

Serialized Form

Nested Class Summary

Nested classes inherited from class javax.swing.JOptionPane

javax.swing.JOptionPane.AccessibleJOptionPane

Nested classes inherited from class javax.swing.JComponent

javax.swing.JComponent.AccessibleJComponent

Nested classes inherited from class java.awt.Container

java.awt.Container.AccessibleAWTContainer

Nested classes inherited from class java.awt.Component

java.awt.Component.AccessibleAWTComponent,
java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy

Field Summary
Fields inherited from class javax.swing.JOptionPane

CANCEL_OPTION, CLOSED_OPTION, DEFAULT_OPTION, ERROR_MESSAGE, icon,


ICON_PROPERTY, INFORMATION_MESSAGE, INITIAL_SELECTION_VALUE_PROPERTY,
INITIAL_VALUE_PROPERTY, initialSelectionValue, initialValue,
INPUT_VALUE_PROPERTY, inputValue, message, MESSAGE_PROPERTY,
MESSAGE_TYPE_PROPERTY, messageType, NO_OPTION, OK_CANCEL_OPTION, OK_OPTION,
OPTION_TYPE_PROPERTY, options, OPTIONS_PROPERTY, optionType, PLAIN_MESSAGE,
QUESTION_MESSAGE, SELECTION_VALUES_PROPERTY, selectionValues,
UNINITIALIZED_VALUE, value, VALUE_PROPERTY, WANTS_INPUT_PROPERTY, wantsInput,
WARNING_MESSAGE, YES_NO_CANCEL_OPTION, YES_NO_OPTION, YES_OPTION

Fields inherited from class javax.swing.JComponent

accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION,


WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW

Fields inherited from class java.awt.Component

BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT,


TOP_ALIGNMENT

Fields inherited from interface java.awt.image.ImageObserver

ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH

Method Summary
static java.lang.String showMultiInputDialog(java.awt.Component parentCompone
[] nt, java.lang.String[] prompts)

Pop up a dialog asking for multiple items of input

static java.lang.String showMultiInputDialog(java.awt.Component parentCompone


[] nt, java.lang.String[] prompts,
java.lang.String title)
Pop up a dialog asking for multiple items of input

static java.lang.String showMultiInputDialog(java.awt.Component parentCompone


[] nt, java.lang.String[] prompts,
java.lang.String[] initialValues)
Pop up a dialog asking for multiple items of input

static java.lang.String showMultiInputDialog(java.awt.Component parentCompone


[] nt, java.lang.String[] prompts,
java.lang.String[] initialValues,
java.lang.String title)
Pop up a dialog asking for multiple items of input

Methods inherited from class javax.swing.JOptionPane

createDialog, createInternalFrame, getAccessibleContext,


getDesktopPaneForComponent, getFrameForComponent, getIcon,
getInitialSelectionValue, getInitialValue, getInputValue,
getMaxCharactersPerLineCount, getMessage, getMessageType, getOptions,
getOptionType, getRootFrame, getSelectionValues, getUI, getUIClassID,
getValue, getWantsInput, paramString, selectInitialValue, setIcon,
setInitialSelectionValue, setInitialValue, setInputValue, setMessage,
setMessageType, setOptions, setOptionType, setRootFrame, setSelectionValues,
setUI, setValue, setWantsInput, showConfirmDialog, showConfirmDialog,
showConfirmDialog, showConfirmDialog, showInputDialog, showInputDialog,
showInputDialog, showInputDialog, showInputDialog, showInputDialog,
showInternalConfirmDialog, showInternalConfirmDialog,
showInternalConfirmDialog, showInternalConfirmDialog,
showInternalInputDialog, showInternalInputDialog, showInternalInputDialog,
showInternalMessageDialog, showInternalMessageDialog,
showInternalMessageDialog, showInternalOptionDialog, showMessageDialog,
showMessageDialog, showMessageDialog, showOptionDialog, updateUI

Methods inherited from class javax.swing.JComponent

addAncestorListener, addNotify, addPropertyChangeListener,


addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect,
contains, createToolTip, disable, enable, firePropertyChange,
firePropertyChange, firePropertyChange, firePropertyChange,
firePropertyChange, firePropertyChange, firePropertyChange,
firePropertyChange, firePropertyChange, fireVetoableChange,
getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY,
getAncestorListeners, getAutoscrolls, getBorder, getBounds,
getClientProperty, getComponentGraphics, getConditionForKeyStroke,
getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight,
getInputMap, getInputMap, getInputVerifier, getInsets, getInsets,
getListeners, getLocation, getMaximumSize, getMinimumSize,
getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners,
getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize,
getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor,
getTransferHandler, getVerifyInputWhenFocusTarget,
getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus,
isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet,
isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile,
isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint,
paintBorder, paintChildren, paintComponent, paintImmediately,
paintImmediately, print, printAll, printBorder, printChildren,
printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent,
processMouseMotionEvent, putClientProperty, registerKeyboardAction,
registerKeyboardAction, removeAncestorListener, removeNotify,
removePropertyChangeListener, removePropertyChangeListener,
removeVetoableChangeListener, repaint, repaint, requestDefaultFocus,
requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow,
resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap,
setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder,
setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled,
setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize,
setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize,
setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI,
setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update

Methods inherited from class java.awt.Container

add, add, add, add, add, addContainerListener, addImpl,


applyComponentOrientation, areFocusTraversalKeysSet, countComponents,
deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent,
getComponentAt, getComponentAt, getComponentCount, getComponents,
getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy,
getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot,
isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate,
minimumSize, paintComponents, preferredSize, printComponents,
processContainerEvent, processEvent, remove, remove, removeAll,
removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys,
setFocusTraversalPolicy, setLayout, transferFocusBackward,
transferFocusDownCycle, validate, validateTree

Methods inherited from class java.awt.Component

action, add, addComponentListener, addFocusListener,


addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener,
addKeyListener, addMouseListener, addMouseMotionListener,
addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents,
contains, createImage, createImage, createVolatileImage, createVolatileImage,
disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods,
getBackground, getBounds, getColorModel, getComponentListeners,
getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor,
getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics,
getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners,
getHierarchyListeners, getIgnoreRepaint, getInputContext,
getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale,
getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners,
getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit,
getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside,
isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable,
isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight,
isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location,
lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp,
move, nextFocus, paintAll, postEvent, prepareImage, prepareImage,
processComponentEvent, processFocusEvent, processHierarchyBoundsEvent,
processHierarchyEvent, processInputMethodEvent, processMouseEvent,
processMouseWheelEvent, remove, removeComponentListener, removeFocusListener,
removeHierarchyBoundsListener, removeHierarchyListener,
removeInputMethodListener, removeKeyListener, removeMouseListener,
removeMouseMotionListener, removeMouseWheelListener, repaint, repaint,
repaint, resize, resize, setBounds, setBounds, setComponentOrientation,
setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled,
setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize,
setSize, show, show, size, toString, transferFocus, transferFocusUpCycle

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait,


wait
Method Detail

showMultiInputDialog
public static java.lang.String[]
showMultiInputDialog(java.awt.Component parentComponent,

java.lang.String[] prompts,

java.lang.String[] initialValues,
java.lang.String title)
Pop up a dialog asking for multiple items of input

Parameters:

parentComponent - the parent Component of the dialog that is shown

prompts - the prompts to display

initialValues - the initial values to display for each item - this parameter can
be null, in which case no initial values are specified; or individual elements can
be null, indicating that no initial value is specified for a particular field

title - the title for this dialog

Returns:

an array of values corresponding to the various prompts, or null if the user


cancelled

showMultiInputDialog
public static java.lang.String[]
showMultiInputDialog(java.awt.Component parentComponent,

java.lang.String[] prompts,
java.lang.String title)
Pop up a dialog asking for multiple items of input

Parameters:
parentComponent - the parent Component of the dialog that is shown

prompts - the prompts to display

title - the title for this dialog

Returns:

an array of values corresponding to the various prompts, or null if the user


cancelled

showMultiInputDialog
public static java.lang.String[]
showMultiInputDialog(java.awt.Component parentComponent,

java.lang.String[] prompts,

java.lang.String[] initialValues)
Pop up a dialog asking for multiple items of input

Parameters:

parentComponent - the parent Component of the dialog that is shown

prompts - the prompts to display

initialValues - the initial values to display for each item - this parameter can
be null, in which case no initial values are specified; or individual elements can
be null, indicating that no initial value is specified for a particular field

Returns:

an array of values corresponding to the various prompts, or null if the user


cancelled

showMultiInputDialog
public static java.lang.String[]
showMultiInputDialog(java.awt.Component parentComponent,
java.lang.String[] prompts)
Pop up a dialog asking for multiple items of input

Parameters:

parentComponent - the parent Component of the dialog that is shown

prompts - the prompts to display

Returns:

an array of values corresponding to the various prompts, or null if the user


cancelled

Class Person
java.lang.Object
Person
All Implemented Interfaces:

java.io.Serializable

public class Person

extends java.lang.Object

implements java.io.Serializable

An object of this class maintains information about a single individual in the address
book

See Also:

Serialized Form

Nested Class Summary


static class
Person.CompareByName
Comparator for comparing two persons by alphabetical order of
name

static class Person.CompareByZip

Comparator for comparing two persons by order of zip code

Constructor Summary
Person(java.lang.String firstName, java.lang.String lastName,
java.lang.String address, java.lang.String city, java.lang.String state,
java.lang.String zip, java.lang.String phone)
Constructor

Method Summary
java.lang.String getAddress()

Accessor for the person's address

java.lang.String getCity()

Accessor for the person's city

java.lang.String getFirstName()

Accessor for the person's first name

java.lang.String getLastName()

Accessor for the person's last name

java.lang.String getPhone()

Accessor for the person's phone

java.lang.String
getState()
Accessor for the person's state

java.lang.String getZip()

Accessor for the person's zip

void update(java.lang.String address, java.lang.String city,


java.lang.String state, java.lang.String zip,
java.lang.String phone)
Update the person with new information.

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString,


wait, wait, wait

Constructor Detail

Person
public Person(java.lang.String firstName,
java.lang.String lastName,
java.lang.String address,
java.lang.String city,
java.lang.String state,
java.lang.String zip,
java.lang.String phone)
Constructor

Parameters:

firstName - the person's first name

lastName - the person's last name

address - the person's address

city - the person's city


state - the person's state

zip - the person's zip

phone - the person's phone

Method Detail

getFirstName
public java.lang.String getFirstName()
Accessor for the person's first name

Returns:

the person's first name

getLastName
public java.lang.String getLastName()
Accessor for the person's last name

Returns:

the person's last name

getAddress
public java.lang.String getAddress()
Accessor for the person's address

Returns:

the person's address

getCity
public java.lang.String getCity()
Accessor for the person's city

Returns:

the person's city

getState
public java.lang.String getState()
Accessor for the person's state

Returns:

the person's state

getZip
public java.lang.String getZip()
Accessor for the person's zip

Returns:

the person's zip

getPhone
public java.lang.String getPhone()
Accessor for the person's phone

Returns:

the person's phone

update
public void update(java.lang.String address,
java.lang.String city,
java.lang.String state,
java.lang.String zip,
java.lang.String phone)
Update the person with new information. Note that the name cannot be
changed, but the other information can be

Parameters:

address - the person's new address

city - the person's new city

state - the person's new state

zip - the person's new zip

phone - the person's new phone

Class Person.CompareByName
java.lang.Object
Person.CompareByName
All Implemented Interfaces:

java.util.Comparator

Enclosing class:

Person

public static class Person.CompareByName

extends java.lang.Object

implements java.util.Comparator

Comparator for comparing two persons by alphabetical order of name

Constructor Summary
Person.CompareByName()

Method Summary
int compare(java.lang.Object person1, java.lang.Object person2)

Compare two objects (which must both be Persons) by last name,


with ties broken by first name

boolean equals(java.lang.Object person1, java.lang.Object person2)

Compare two objects (which must both be Persons) by name

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString,


wait, wait, wait

Methods inherited from interface java.util.Comparator

equals

Constructor Detail

Person.CompareByName
public Person.CompareByName()

Method Detail
compare
public int compare(java.lang.Object person1,
java.lang.Object person2)
Compare two objects (which must both be Persons) by last name, with ties
broken by first name

Specified by:

compare in interface java.util.Comparator

Parameters:

person1 - the first object

person2 - the second object

Returns:

a negative number if person1 belongs before person2 in alphabetical order of


name; 0 if they are equal; a positive number if person1 belongs after person2

Throws:

java.lang.ClassCastException - if either parameter is not a Person object

equals
public boolean equals(java.lang.Object person1,
java.lang.Object person2)
Compare two objects (which must both be Persons) by name

Parameters:

person1 - the first object

person2 - the second object

Returns:

true if they have the same name, false if they do not


Throws:

java.lang.ClassCastException - if either parameter is not a Person object

Class Person.CompareByZip
java.lang.Object
Person.CompareByZip
All Implemented Interfaces:

java.util.Comparator

Enclosing class:

Person

public static class Person.CompareByZip

extends java.lang.Object

implements java.util.Comparator

Comparator for comparing two persons by order of zip code

Constructor Summary

Person.CompareByZip()

Method Summary
int compare(java.lang.Object person1, java.lang.Object person2)

Compare two objects (which must both be Persons) by zip

boolean
equals(java.lang.Object person1, java.lang.Object person2)
Compare two objects (which must both be Persons) by zip

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString,


wait, wait, wait

Methods inherited from interface java.util.Comparator

equals

Constructor Detail

Person.CompareByZip
public Person.CompareByZip()

Method Detail

compare
public int compare(java.lang.Object person1,
java.lang.Object person2)
Compare two objects (which must both be Persons) by zip

Specified by:

compare in interface java.util.Comparator

Parameters:

person1 - the first object

person2 - the second object


Returns:

a negative number if person1 belongs before person2 in order of zip; 0 if they


are equal; a positive number if person1 belongs after person2

Throws:

java.lang.ClassCastException - if either parameter is not a Person object

equals
public boolean equals(java.lang.Object person1,
java.lang.Object person2)
Compare two objects (which must both be Persons) by zip

Parameters:

person1 - the first object

person2 - the second object

Returns:

true if they have the same zip, false if they do not

Throws:

java.lang.ClassCastException - if either parameter is not a Person object

You might also like