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.
Use spApp as your application. This application has four components:
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.
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.