CSC 365- Programming project 4 (Extra Credit)--(Due December 14th, 2005)


Real Objects for Vertices

Convert the adjacency matrix in your weightedGraph class to allow for any object to be represented as a node/vertex. In the current version, numbers 0,1,.. represent our nodes; there are very few applications where such numbered nodes are useful. It is best for nodes to be any type of object. For example, why shouldn't each node be a different color object or a graphic object on the screen.

To make this happen, you will extend your weightedGraph class and create a new class objectGraph. objectGraph has an object field in its graphNode class with a supporting method such as addVertex(). g_.length could no longer be the best tool for determining how many nodes you really have, you may need to maintain a size_ field to keep track of count of the cells in g_ that are occupied. You may also need to change the notion of source and destination for finding shortest path, as well as, from and to when adding edges.

You should be able to use my test1 with the obvious modifications to test your changes.

A Shortest Path Application

Use spApp as your application. This application has four components:

graphImage

The applications MouseEventDemo and MouseMotionEventDemo demo implementing mouse listener. These demo programs will require you to download the class BlankArea. Of course, none of these three files have anything directly to do with this project.

You need to implement MouseListener when developing graphImage; in its constructor put in addMouseListener(this);; and add the mouse event handling methods shown in the demo programs.

This class needs to extend JPanel and requires a paintComponent method. paintComponent should display the graph and a shortest path (if one exists). You need to issue repaint in your even handlers when you see fit.

nodeImage

You will need a nodeImage class that represent our nodes on the screen. Clearly, they need to know their color and coordinates. Such objects also need at least an equals method that compares them against each other. Writing a method like length that would calculate the distance between two nodes would be useful as we could use the result of such a method as the weigth of an edge connecting two nodes.