Java Reference
In-Depth Information
database initially is created, adding a temporary user ID and password that can be
deleted after permanent user data is entered. In order for a working database to
be available for subsequent use, the MakeDB.java program is developed first.
Another new class, StockTrackerDB, provides an interface to the database
independent of the application using the database. Placing the database access
methods in a separate class allows for more than one application to use the data-
base in a consistent fashion. This allows the functionality of the database to be
independent of the user interface, as the requirements document indicates. The
StockTrackerDB class provides the capability for the GUI program to add, delete,
update, and list users, as well as maintain stocks and user stock lists. It is the sec-
ond class developed in this chapter.
All other code not previously developed is provided on the Data Disk. The
first source code provided is STLogon.java, which is provided to create the initial
log on window, similar to the LogonFrame class from the previous chapter. The
STLogon class allows users to log on to the system using a unique user ID. It also
incorporates the main() method from the StockListDemo class, which, therefore,
no longer is needed.
The next source code provided on the Data Disk is the stock-tracking appli-
cation itself, StockTracker.java. This application associates a list of stocks with a
given user and presents that list in a GUI format. It allows administrative users
access to user maintenance and maintains a drop-down list of stock holdings for
the current user. If the user has any existing stock holdings, the first stock sym-
bol appears in the drop-down list box. The stocks are maintained in alphabetic
order using all capital letters. If the user has no stocks, the list box is empty.
Stocks that are added to the user's holdings do not affect the stock holdings of
other users. When deleted from the list, the stock and its description are deleted
from the database, but only if no other users hold that particular stock. Whether
adding or deleting a stock holding, users can type a stock symbol in the stock
text box. If deleting, users may select an existing stock holding from their drop-
down list. As indicated earlier, all database interaction is performed through the
data access class, StockTrackerDB.
The Data Disk also contains the source code, UserMaintFrame.java, which
provides the GUI for adding new users and for updating, deleting, and listing
existing user data. This GUI does not display the stocks associated with a user;
however, if a user is deleted, all stock holdings for the deleted user are removed
from the database, as well. This functionality is available only to administrative
users. This GUI provides a series of windows appropriate for the performing
function, which is communicated from the main application class, StockTracker.
Again, all database interaction is performed through the data access class,
StockTrackerDB.
A User class is necessary for this application; however, the User class from
the previous chapter is insufficient and requires a number of changes to hold
additional information. Therefore, an updated source code file, User.java, incor-
porating the needed changes is provided on the Data Disk.
Finally, a new interface in the source code file, STAction.java, provides a set
of named constant values used by the StockTracker class when requesting
behavior from the UserMaintFrame class. As you have seen, interfaces typically
are small files and may consist of only constants with no method headers. The
STAction interface provides for a consistent use of some constant values and also
is provided on the Data Disk.
Search WWH ::




Custom Search