Graphing Example

Download the graphing package from (Local Mirror). Using your favorite file transfer program, upload the archive to your cunix account. Untar the file using:

tar -xzvf graph.tar.gz

Once you unarchive the file, the graphing classes are already compiled so you should not need to recompile, but if you want to use the following command:

javac -d ./graph/classes/ ./graph/source/*.java

(The directories in the command above assume you are in the directory that contains the graph directory. You can adjust the path accordingly if you organize your files differently.)

To compile your own code (here is a simple example file I wrote), you'll need to specify the location of the graph classes, and you'll want to have the compiler place your class into the same directory. Do this using the following command:

javac -d ./graph/classes/ -classpath ./graph/classes/

The "-d" option tells the compiler to put your compiled class into the ./graph/classes/ directory, while the -classpath option tell the compiler to look in ./graph/classes/ for imported packages (in this case, the graph package).

To run your applet, you'll need a simple web template (here's the simplest one you could make. Following the link should show a broken applet because the growthrates program is not compiled yet). Note that the html code indicates the location of all the classes the applet will need: in particular, the graph classes.

<applet code=growthrates.class width=400 height=400 codebase=./graph/classes></applet>
</html >

There are now a couple ways you can run your applet listed below in order of preference.

If you have X-windows

Once you have these files set up, you can run appletviewer to view the applet using the correct version of Java.

appletviewer viewer.html

This is the best way to run the applet to ensure compatibility. Unfortunately Columbia does not provide free X-windows software. The CUIT computer lab Windows machines should all have X-windows installed. Mac OS X and Linux users should have X windows built in and can set up the connection by typing
ssh -Y

If you don't have X-windows

Alternatively, you can post the applet in your web space by making a public_html directory in your home directory, and giving it permissions so anyone can read and execute it via "chmod a+rx public_html". Unfortunately this method will be dependent on the version of the Java plugin you have in your browser and is subject to annoyances such as browser caching.

First check if you have the correct Java version for this method to work. The CUNIX machines have Java 1.6.0_11, so you'll need something like "application/x-java-applet;version=1.6" listed in your browser's plugin info. Mac OS X seems to only have version 1.5 available so this method is probably only going to work for Windows and Linux users.

Make your public_html directory via "mkdir public_html". Then set its permissions to let everyone read/execute via "chmod a+rx public_html". Next copy in your html applet viewer file (viewer.html) and your compiled applet. Then chmod all of those files to a+rx as well.

Finally, load your web page in your browser by going to
(Of course, with your UNI instead of uni1234.) You should see the applet in your browser. Note that the browser often caches Java applets so if you change the code and recompile, changes may not show up until you use a force reload, which loads the contents of the web page regardless of if it is cached.

If your browser's Java is incompatible

Finally, the least recommended, but possibly necessary option is to compile the code on your computer using whatever version of Java you have available. This at least guarantees compatibility and means you'll Most code we will be writing in the class only requires Java 5 to run so you shouldn't have any major compatibility problems with the course policy that your code will be graded based on how it runs on CUNIX. This means you are responsible for making sure your code runs the way you want it to on CUNIX, so one method of doing that is to develop on your own machine, and go to a computer lab to test it one last time before submitting.


Make sure to check out the other examples included by the author of the graph package. In particular, examples 1 and 1a are probably the most relevant. My example is more bare-bones and shows how little you need to do to make a simple plot. For example, I mostly used the default style settings, which look reasonably good. Feel free to fiddle with the colors/fonts/etc.

Finally, I'm setting up a discussion group in Courseworks on the topic of running applets, since any problems you have will likely be common problems, and I may not have addressed every possible issue in this document. Let's use that forum to discuss this further and we'll try to work out all the necessary details together. I'll add any helpful comments from the web board to this document as well.