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.
Each file entry should consist of a "key" string (e.g. a person's
name or ID, a book's author or ISBN, etc) and one or more
strings representing associated data fields.
You may choose to lay out these fields in your text
file on consecutive lines, e.g.
key
data1
data2
key
data1
data2
...
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 objects stored 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. The list should
display the key strings for your file entries.
- Text fields and/or text areas for displaying, entering and
modifying data fields in your file entries.
- Buttons to add and
delete entries, and a means of modifying existing entries.
Try to add one or two other features relevant to your chosen
application.
Development Platform
You may be able to develop and run your Swing-based program on
sirah or the other course hosts. However this is only likely
to work if you are logging in from a computer that can display
remote X-Windows based applications--perhaps a UNIX workstation or
a PC running Hummingbird Exceed. Even then
you may still have problems displaying the remote graphical application
if there is a firewall between you and sirah.
So in general I recommend you develop your GUI application locally on
your PC or workstation instead.
If necessary (and allowed), you can download Java software from
SDK 1.2
or
SDK 1.3.
Please let me know if this is impractical for you.
I will accept software developed with any version of Java that includes
the Swing set.
Submission of your Homework
Your submission should consist of files including
-
A description of your program and the format of your data file,
preferably in Microsoft Word,
HTML, or plain text format,
- all Java source code, and
- an example data file.
You may optionally include javadoc documentation as .html
files. However this cannot be submitted in place of your main document.
On sirah you will find a directory called
/home/project/it1spring01/homework2/uid where
uid is your login ID. To submit Assignment 2,
please copy your files into this directory.
Grading
For this assignment, there will be a total of 20 points.
Grading criteria are similar to
Assignment 1.
Some points will be assigned on the basis of apparent effort and
uniqueness, and on the extent to which your application presents an
attractive and intuitive GUI.
Useful resources
Simple Swing examples
You will find most of the Swing components you are likely to need
illustrated in the
examples
from the lectures.
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 use of collection classes
I have added a few extra slides on Vector and
Hashmap to the online lectures on the Java language.
See slides 71 to 76.
The Standard API classes
Including Swing, see
the Java 2 API specification.
Please send questions to Bryan Carpenter at dbc@csit.fsu.edu.