CS 2121 Introduction to Java:
Programming Assignment 5
Due April 23, 30 points
For this lab you will write a program for viewing files.
Unlike your previous programming assignments, which have been applets,
this program is a stand-alone application.
This is necessary because the program accesses files.
This capability is denied to applets for security reasons.
There are two classes in the program, FileViewPane and FileViewer.
The FileViewPane class encapsulates a JTextArea for displaying text, along
with a JScrollPane to support scrolling through text that is too big to fit
in the text area.
It also provides methods for reading from a file into the text area and for
saving the contents of the text area to a file.
It is intended as a reusable class.
The next programming assignment will make use of two FileViewPane objects.
The FileViewer class subclasses the JFrame class to provide a top-level
window for the program.
It is a showcase for many of the Swing features, including dialogs, menus,
and toolbars.
The development of this program is broken up into the following steps.
-
Step 1 -
In this step, you will setup preliminary versions of the FileViewer and
FileViewPane classes.
The program at this time only displays a text area with a titled border.
Its only functionality is terminating when a user clicks on the close
button in the window frame.
-
Step 2 -
In this step you will add a "File" menu to the application.
Initially it only has an "Exit" menu item.
When a user selects this menu item, the program terminates.
-
Step 3 -
In this step you will add the capability of reading text from a file into
the application's text area.
You will be adding an "Open..." menu item to the "File" menu.
When a user selects this menu item, a dialog for selecting a file pops up.
After the user makes a selection, the contents of the selected file appears
in the text area.
-
Step 4 -
In this step you will add the capability of saving text from the text area
to a file.
You will be adding an "Save As..." menu item to the "File" menu.
When a user selects this menu item, a dialog for selecting a file pops up.
After the user makes a selection, the contents of the text area is saved to
the selected file.
-
Step 5 -
In this step you will add a tool bar to the application.
The tool bar contains buttons that duplicate the actions of the "Open...",
"Save As ...", and "Exit" menu items.
Each button displays an icon for the action.
When the cursor is moved over one of the buttons a short description of
what it does (a tool tip) pops up.
The tool bar is movable.
It starts at the top of the application window, just beneath the menu bar.
It can be dragged to the left or right side, the bottom, or into its own
top-level window.
All of the new functionality of this step is accomplished with only 11
lines of code.