Writing a Java application with Swing components
You are asked to write a Java application to manipulate entries
in a text file. The program must have a Graphical User Interface using
Swing components.
Choose a meaningful interpretation for the entries stored in your
file. They might be names and addresses, or titles and bibliographic
information, or something more imaginative. Bear in mind that in
future homeworks you will be invited to develop the program you submit
here into a client-server distributed application, accessing a database
on a remote machine. Try to choose an example that lends itself to
these future developments.
Most likely the file entries will consist of a key string and one or more
strings representing data fields. You may choose to lay these out in your text
file on consecutive lines, eg
key1
data1
key2
data2
...
If your data fields can run over several lines, you might use
lines containing a reserved string pattern to separate the entries.
Your program should be able to read the whole text file and store all entries in
internal data structures of your design. One convenient possibility
may be to store the keys in a
javax.swing.DefaultListModel and to store the data
fields in a java.util.HashMap. The program should
also be able to save the modified data structures back to the text
file in the original format.
The graphical user interface should have at least
- A scrollable list component for selecting entries.
- Buttons to add and
delete entries, and a means of modifying existing entries.
- Text fields and/or text areas for displaying, entering and
modifying entries.
Try to add one or two other features relevant to your chosen
application. But don't make the program overly elaborate, otherwise
it may become difficult to adapt in future homeworks. (For example
there may not be much point adding an elaborate file chooser, because
this will become irrelevant if the data is stored in remote a database.)
To submit your homework, include
-
a document describing the application,
the file format, and the program;
- the .java source
file(s) and (optionally) .class files;
- (optionally) javadoc documentation as
.html files; and
- an example data file.
As usual, the code should be nicely organized and documented.
In coding, try to follow the major recommendations in Sun's
Code Conventions for the Java Programming Language.
Long lines or bad indentation policy make code difficult for the
graders to read, and this could affect your mark.
Simple reading and writing of text files
Since this wasn't covered in class, there is an example that reads
lines in a text file, and writes them back to another text file, in
here.
Simple Swing examples
You will find most of the Swing components you are likely to need
illustrated in the
examples
from the lectures.
Running Swing applications
You may be able to develop and run your Swing-based program on
sirah or the other course hosts. But in general this
will only work if you are logging in from a computer that can display
remote X-Windows based applications.
If you are logging in from a Windows PC that does not have
special software (e.g. Hummingbird Exceed) installed
to display X applications, you will not be able to view Swing
applications running on sirah.
Instead you should consider downloading and installing
JDK on your
PC and testing locally.
Please send questions to Bryan Carpenter at dbc@csit.fsu.edu.