MARK SWEETING
sweeting.org home the sweeting genealogy project mark sweeting's home search sweeting.org contact me
You are here: Home > Mark Sweeting > Something for the Public > Demonstration Applets

Previous | Next

PART 4 - DEMONSTRATION APPLETS

A pair of demonstration applets and a servlet have been written to accompany this work and can be found on the disk included. The intention of these is to illustrate some of the relevant capabilities of Java, and not to provide a working solution for the NMR!

The first applet - viewer.class - is designed to illustrate an applets ability to connect to a server to read in (vector) data from a file stored on it. The data file in this case contains information on the points, lines (or "polylines") and polygons that make up a site plan or map. Each map object (point, line or polygon) can be added to one of ten "layers" that are each individually colour coded. The user has the freedom to turn these layers on and off at will.

Modes include "pan", "zoom in", "zoom out", and "query map", and they do exactly as you would expect them too. The query mode allows you to click on polygons or points and select them. Once selected, the object is highlighted and the text description for that object is displayed in the status bar of the applet. At the moment, I have not worked out an efficient way to enable the selection of lines.

The second applet - digitiser.class - provides the user with the ability to digitise raster images by hand on screen. Due to the security features of Java, applets may only read data from the machine they are loaded from unless the applet is signed with a user approved security certificate. The applet presented here reads a raster file of the disk and displays it on the screen. Controls include the mode buttons - add polygon, add line, add point and pan, an "undo" button, and an "export" button. There is a status bar to keep the user informed, and a text entry field to allows the entry of text descriptions for individual objects. There is also a layer control panel that controls which layer the current object is added to.

Having digitised an image, the user presses the export button. The applet then connects to a Java servlet (server.class) on the remote server running on port 4444 (by default). Once connected, the applet and servlet confirm they are both who they should be. Assuming everything is OK, the applet sends all its data back to the servlet, and the servlet writes this information to a randomly named file. Once the server has received all the data, it sends a message back to the applet to inform the user of the file name just used. The connection is then closed.

This file name may then be used in the parameter tag of the viewer applet, to enable this digitised map to be published over the WWW as a "dynamic" or "active" map.

As these applets are for illustrative purposes only, they do not connect to a database to exchange data, and do no allow any querying of data. The principle would be fairly similar though: The getConnection(String) method used with JDBC is very similar to url.openStream() method used in the viewer applet, where String would be similar to jdbc:dbprot://localhost:4444/testdb/, and url would be similar to http://localhost:444/. Java handles many of its network, I/O and database connections in a similar manner, as they are all really a subset of "java.io".