Step 1


Overview

All of the code for this step is provided for you. All you need to do is get a copy of the Java source code files, read their comments, compile them, and run the program.

Unlike your previous assignments, this program is a stand-alone application. This means that the program is run directly from the command line, rather than being started up by a browser. A stand-alone application is defined as by extending the JFrame class, instead of the JApplet class used in an applet.

Obtaining the Java Source Code Files

The Java source code files are bundled up into a single file called a jar file. This is similar to a zip file. The Java software development kit has a program named "jar" for creating and unbundling jar files. To obtain the files, you should execute the following commands in a UNIX terminal window.
    cp ~gshute/public/cs2121/pa5-6.jar .
    jar xf pa5-6.jar
    rm pa5-6.jar
    cd pa5-6
    ls
The first command copies the jar file to your own directory. The second unbundles it. This should create a new directory named "pa5-6". The third command removes the jar file, which is no longer needed. The fourth moves you into the pa5-6 directory, where you will do your work for the remaining programming assignments. The fifth displays the files contained in the new directory. You should see the following files.

The three .gif files are image files. They contain icons that you will use later for toolbar buttons. The two .java files are the source code files that you will be modifying in later steps. You should read the comments in these files to get an idea how the program works.

Compiling the Source Code Files

Compilation for a stand-alone application is no different than compilation of an applet. You can just give the following command.
    javac *.java
You should not see any error messages.

Running the Program

A stand-alone application is executed with the java command, specifying the name of the class that contains the main() method as an argument. For this program, you should give the following command.
    java FileViewer

The program title, "File Viewer", should appear in the title bar at the top of the application window. The program should also display a text area with a scrollbar on the right side. It should be enclosed in a border with the title "File Contents". If you click in the text area and then type text at the keyboard, it should appear in the text area. Other than that, there is not much that you can do with the program at this time except to click on the close button in the title bar. The window should disppear.

If everything works as described, you are ready for Step 2.