carfield.com.hk AbstractGraphSearch.java 2002-01-20T16:00:00Z 2002-01-20T16:00:00Z <br/><TEXTAREA name="code" class="java" rows="16" cols="100">import java.util.Vector; abstract public class AbstractGraphSearch { public void addNode(String name, int x, int y) { System.out.println(&quot;Adding node: &quot; + name + &quot;, &quot; + x + &quot;, &quot; + y); nodeNames[numNodes] = name; node_x[numNodes] = x; node_y[numNodes] = y; numNodes++; } public int getNumNodes() { return numNodes; } public int getNumLinks() { return numLinks; } public String getNodeName(int index) { try { return nodeNames[index]; } catch (Exception e) { System.out.println(&quot;Error in getNodeName: &quot; + e); } return &quot;no name&quot;; // error condition } public int getNodeX(int index) { try { return node_x[index]; } catch (Exception e) { System.out.println(&quot;Error in getNodePosition: &quot; + e); } return 0; // error condition } public int getNodeY(int index) { try { return node_y[index]; } catch (Exception e) { System.out.println(&quot;Error in getNodePosition: &quot; + e); } return 0; // error condition } public int getLink1(int index) { return link_1[index]; } public int getLink2(int index) { return link_2[index]; } public void addLink(int node1, int node2) { link_1[numLinks] = node1; link_2[numLinks] = node2; int dist_squared = (node_x[node1] - node_x[node2]) * (node_x[node1] - node_x[node2]) + (node_y[node1] - node_y[node2]) * (node_y[node1] - node_y[node2]); lengths[numLinks] = (int)Math.sqrt(dist_squared); numLinks++; } public void addLink(String name1, String name2) { int index1 = -1, index2 = -1; for (int i=0; i&lt;numNodes; i++) { if (name1.equals(nodeNames[i])) index1 = i; if (name2.equals(nodeNames[i])) index2 = i; } if (index1 != -1 &amp;&amp; index2 != -1) addLink(index1, index2); } /** findPath - abstract method that is defined in subclasses */ abstract public int [] findPath(int start_node, int goal_node); // return an array of node indices protected int getNodeIndex(String name) { for (int i=0; i&lt;numNodes; i++) { if (name.equals(nodeNames[i])) return i; } return -1; // error condition } final public static int MAX = 50; // max number of nodes and max number of links protected int [] path = new int[AbstractGraphSearch.MAX]; protected int num_path = 0; // for nodes: protected String [] nodeNames = new String[MAX]; protected int [] node_x = new int[MAX]; protected int [] node_y = new int[MAX]; // for links between nodes: protected int [] link_1 = new int[MAX]; protected int [] link_2 = new int[MAX]; protected int [] lengths = new int[MAX]; protected int numNodes = 0; protected int numLinks = 0; protected int goalNodeIndex = -1, startNodeIndex = -1; } </TEXTAREA><br><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2002-01-20T16:00:00Z BreadthFirstSearch.java 2002-01-20T16:00:00Z 2002-01-20T16:00:00Z <br/><TEXTAREA name="code" class="java" rows="16" cols="100">public class BreadthFirstSearch extends AbstractGraphSearch { /** findPath - abstract method in super class */ public int [] findPath(int start_node, int goal_node) { // return an array of node indices System.out.println(&quot;Entered BreadthFirstSearch.findPath(&quot; + start_node + &quot;, &quot; + goal_node + &quot;)&quot;); // data structures for depth first search: boolean [] alreadyVisitedFlag = new boolean[numNodes]; int [] predecessor = new int[numNodes]; IntQueue queue = new IntQueue(numNodes + 2); for (int i=0; i&lt;numNodes; i++) { alreadyVisitedFlag[i] = false; predecessor[i] = -1; } alreadyVisitedFlag[start_node] = true; queue.addToBackOfQueue(start_node); outer: while (queue.isEmpty() == false) { int head = queue.peekAtFrontOfQueue(); int [] connected = connected_nodes(head); if (connected != null) { for (int i=0; i&lt;connected.length; i++) { if (alreadyVisitedFlag[connected[i]] == false) { predecessor[connected[i]] = head; queue.addToBackOfQueue(connected[i]); if (connected[i] == goal_node) break outer; // we are done } } alreadyVisitedFlag[head] = true; queue.removeFromQueue(); // ignore return value } } // now calculate the shortest path from the predecessor array: int [] ret = new int[numNodes + 1]; int count = 0; ret[count++] = goal_node; for (int i=0; i&lt;numNodes; i++) { ret[count] = predecessor[ret[count - 1]]; count++; if (ret[count - 1] == start_node) break; // back to starting node } int [] ret2 = new int[count]; for (int i=0; i&lt;count; i++) { ret2[i] = ret[count - 1 - i]; } return ret2; } protected class IntQueue { public IntQueue(int num) { queue = new int[num]; head = tail = 0; len = num; } public IntQueue() { this(400); } private int [] queue; int tail, head, len; public void addToBackOfQueue(int n) { queue[tail] = n; if (tail &gt;= (len - 1)) { tail = 0; } else { tail++; } } public int removeFromQueue() { int ret = queue[head]; if (head &gt;= (len - 1)) { head = 0; } else { head++; } return ret; } public boolean isEmpty() { return head == (tail + 1); } public int peekAtFrontOfQueue() { return queue[head]; } } protected int [] connected_nodes(int node) { int [] ret = new int[AbstractGraphSearch.MAX]; int num = 0; for (int n=0; n&lt;numNodes; n++) { boolean connected = false; // See if there is a link between node 'node' and 'n': for (int i=0; i&lt;numLinks; i++) { if (link_1[i] == node) { if (link_2[i] == n) { connected = true; break; } } if (link_2[i] == node) { if (link_1[i] == n) { connected = true; break; } } } if (connected) { ret[num++] = n; } } if (num == 0) return null; int [] ret2 = new int[num]; for (int i=0; i&lt;num; i++) { ret2[i] = ret[i]; } return ret2; } } </TEXTAREA><br><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2002-01-20T16:00:00Z DepthFirstSearch.java 2002-01-20T16:00:00Z 2002-01-20T16:00:00Z <br/><TEXTAREA name="code" class="java" rows="16" cols="100">public class DepthFirstSearch extends AbstractGraphSearch { /** findPath - abstract method in super class */ public int [] findPath(int start_node, int goal_node) { // return an array of node indices System.out.println(&quot;Entered DepthFirstSearch.findPath(&quot; + start_node + &quot;, &quot; + goal_node + &quot;)&quot;); path[0] = start_node; return findPathHelper(path, 1, goal_node); } public int [] findPathHelper(int [] path, int num_path, int goal_node) { System.out.println(&quot;Entered DepthFirstSearch.findPathHelper(...,&quot; + num_path + &quot;, &quot; + goal_node + &quot;)&quot;); if (goal_node == path[num_path - 1]) { int [] ret = new int[num_path]; for (int i=0; i&lt;num_path; i++) ret[i] = path[i]; return ret; // we are done! } int [] new_nodes = connected_nodes(path, num_path); if (new_nodes != null) { for (int j=0; j&lt;new_nodes.length; j++) { path[num_path] = new_nodes[j]; int [] test = findPathHelper(path, num_path + 1, goal_node); if (test != null) { if (test[test.length - 1] == goal_node) { return test; } } } } return null; } protected int [] connected_nodes(int [] path, int num_path) { // find all nodes connected to the last node on 'path' // that are not already on 'path' int [] ret = new int[AbstractGraphSearch.MAX]; int num = 0; int last_node = path[num_path - 1]; for (int n=0; n&lt;numNodes; n++) { // see if node 'n' is already on 'path': boolean keep = true; for (int i=0; i&lt;num_path; i++) { if (n == path[i]) { keep = false; break; } } boolean connected = false; if (keep) { // now see if there is a link between node 'last_node' and 'n': for (int i=0; i&lt;numLinks; i++) { if (link_1[i] == last_node) { if (link_2[i] == n) { connected = true; break; } } if (link_2[i] == last_node) { if (link_1[i] == n) { connected = true; break; } } } if (connected) { ret[num++] = n; } } } if (num == 0) return null; int [] ret2 = new int[num]; for (int i=0; i&lt;num; i++) { ret2[i] = ret[i]; } return ret2; } } </TEXTAREA><br><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2002-01-20T16:00:00Z GraphBreadthFirstSearch.java 2002-01-20T16:00:00Z 2002-01-20T16:00:00Z <br/><TEXTAREA name="code" class="java" rows="16" cols="100">import javax.swing.*; import java.awt.*; public class GraphBreadthFirstSearch extends JFrame { JPanel jPanel1 = new JPanel(); public GraphBreadthFirstSearch() { BreadthFirstSearch engine = new BreadthFirstSearch(); // Define a test network before calling the super class 'init': engine.addNode(&quot;0&quot;, 20, 40); engine.addNode(&quot;1&quot;, 60, 60); engine.addNode(&quot;2&quot;, 100, 40); engine.addNode(&quot;3&quot;, 50, 110); engine.addNode(&quot;4&quot;, 140, 80); engine.addNode(&quot;5&quot;, 160, 150); engine.addNode(&quot;6&quot;, 200, 80); engine.addNode(&quot;7&quot;, 160, 40); engine.addNode(&quot;8&quot;, 240, 120); engine.addNode(&quot;9&quot;, 260, 90); engine.addLink(0,1); engine.addLink(1,2); engine.addLink(2,3); engine.addLink(2,4); engine.addLink(4,5); engine.addLink(4,6); engine.addLink(6,8); engine.addLink(8,9); engine.addLink(2,7); engine.addLink(7,9); System.out.println(&quot;Before calculating path&quot;); path = engine.findPath(0, 9); System.out.println(&quot;After calculating path:&quot;); for (int i=0; i&lt;path.length; i++) { System.out.println(&quot; node # &quot; + path[i]); } this.engine = engine; try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } private int [] path = null; private BreadthFirstSearch engine = null; public static void main(String[] args) { GraphBreadthFirstSearch graphBreadthFirstSearch1 = new GraphBreadthFirstSearch(); } private void jbInit() throws Exception { this.setDefaultCloseOperation(3); jPanel1.setBackground(Color.white); this.getContentPane().add(jPanel1, BorderLayout.CENTER); this.setSize(290, 180); this.setVisible(true); } protected void paintNode(Graphics g, String name, int x, int y) { int len = name.length() * 10 + 6; int x1 = x - (len / 2); int x2 = x + (len / 2); int y1 = y - 10; int y2 = y + 10; g.setColor(Color.cyan); g.fill3DRect(x1, y1, len, 20, true); g.setColor(Color.black); g.drawString(name, x1 + 4, y2 - 6); } public void paint(Graphics g) { super.paint(g); if (engine != null &amp;&amp; path != null) { int numNodes = engine.getNumNodes(); int numLinks = engine.getNumLinks(); for (int i=0; i&lt;numLinks; i++) { int l1 = engine.getLink1(i); int l2 = engine.getLink2(i); int x1 = engine.getNodeX(l1); int y1 = engine.getNodeY(l1); int x2 = engine.getNodeX(l2); int y2 = engine.getNodeY(l2); g.setColor(Color.lightGray); g.drawLine(x1, y1, x2, y2); } for (int i=1; i&lt;path.length; i++) { int x1 = engine.getNodeX(path[i-1]); int y1 = engine.getNodeY(path[i-1]); int x2 = engine.getNodeX(path[i]); int y2 = engine.getNodeY(path[i]); g.setColor(Color.black); g.drawLine(x1, y1, x2, y2); } for (int i=0; i&lt;numNodes; i++) { int x1 = engine.getNodeX(i); int y1 = engine.getNodeY(i); paintNode(g, engine.getNodeName(i), x1, y1); } } } } </TEXTAREA><br><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2002-01-20T16:00:00Z GraphDepthFirstSearch.java 2002-01-20T16:00:00Z 2002-01-20T16:00:00Z <br/><TEXTAREA name="code" class="java" rows="16" cols="100">import javax.swing.*; import java.awt.*; public class GraphDepthFirstSearch extends JFrame { JPanel jPanel1 = new JPanel(); public GraphDepthFirstSearch() { DepthFirstSearch engine = new DepthFirstSearch(); // Define a test network before calling the super class 'init': engine.addNode(&quot;0&quot;, 20, 40); engine.addNode(&quot;1&quot;, 60, 60); engine.addNode(&quot;2&quot;, 100, 40); engine.addNode(&quot;3&quot;, 50, 110); engine.addNode(&quot;4&quot;, 140, 80); engine.addNode(&quot;5&quot;, 160, 150); engine.addNode(&quot;6&quot;, 200, 80); engine.addNode(&quot;7&quot;, 160, 40); engine.addNode(&quot;8&quot;, 240, 120); engine.addNode(&quot;9&quot;, 260, 90); engine.addLink(0,1); engine.addLink(1,2); engine.addLink(2,3); engine.addLink(2,4); engine.addLink(4,5); engine.addLink(4,6); engine.addLink(6,8); engine.addLink(8,9); engine.addLink(2,7); engine.addLink(7,9); System.out.println(&quot;Before calculating path&quot;); path = engine.findPath(0, 9); System.out.println(&quot;After calculating path:&quot;); for (int i=0; i&lt;path.length; i++) { System.out.println(&quot; node # &quot; + path[i]); } this.engine = engine; try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } private int [] path = null; private DepthFirstSearch engine = null; public static void main(String[] args) { GraphDepthFirstSearch graphDepthFirstSearch1 = new GraphDepthFirstSearch(); } private void jbInit() throws Exception { this.setDefaultCloseOperation(3); jPanel1.setBackground(Color.white); this.getContentPane().add(jPanel1, BorderLayout.CENTER); this.setSize(290, 180); this.setVisible(true); } protected void paintNode(Graphics g, String name, int x, int y) { int len = name.length() * 10 + 6; int x1 = x - (len / 2); int x2 = x + (len / 2); int y1 = y - 10; int y2 = y + 10; g.setColor(Color.cyan); g.fill3DRect(x1, y1, len, 20, true); g.setColor(Color.black); g.drawString(name, x1 + 4, y2 - 6); } public void paint(Graphics g) { super.paint(g); if (engine != null &amp;&amp; path != null) { int numNodes = engine.getNumNodes(); int numLinks = engine.getNumLinks(); for (int i=0; i&lt;numLinks; i++) { int l1 = engine.getLink1(i); int l2 = engine.getLink2(i); int x1 = engine.getNodeX(l1); int y1 = engine.getNodeY(l1); int x2 = engine.getNodeX(l2); int y2 = engine.getNodeY(l2); g.setColor(Color.lightGray); g.drawLine(x1, y1, x2, y2); } for (int i=1; i&lt;path.length; i++) { int x1 = engine.getNodeX(path[i-1]); int y1 = engine.getNodeY(path[i-1]); int x2 = engine.getNodeX(path[i]); int y2 = engine.getNodeY(path[i]); g.setColor(Color.black); g.drawLine(x1, y1, x2, y2); } for (int i=0; i&lt;numNodes; i++) { int x1 = engine.getNodeX(i); int y1 = engine.getNodeY(i); paintNode(g, engine.getNodeName(i), x1, y1); } } } } </TEXTAREA><br><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2002-01-20T16:00:00Z Maze.java 2002-01-19T16:00:00Z 2002-01-19T16:00:00Z <br/><TEXTAREA name="code" class="java" rows="16" cols="100">import java.awt.Dimension; /** * Class Maze - private class for representing search space as a two-dimensional maze */ public class Maze { public static short OBSTICLE = -1; public static short START_LOC_VALUE = -2; public static short GOAL_LOC_VALUE = -3; private int width = 0; private int height = 0; public Dimension startLoc = new Dimension(); public Dimension goalLoc = new Dimension(); /** * The maze (or search space) data is stored as a short integer rather than * as a boolean so that bread-first style searches can use the array to store * search depth. A value of -1 indicates a barrier in the maze. */ private short [][]maze; public Maze(int width, int height) { System.out.println(&quot;New maze of size &quot; + width + &quot; by &quot; + height); this.width = width; this.height = height; maze = new short[width+2][height+2]; for (int i=0; i&lt;width+2; i++) { for (int j=0; j&lt;height+2; j++) { maze[i][j] = 0; } } for (int i=0; i&lt;height+2; i++) { maze[0][i] = maze[width+1][i] = OBSTICLE; } for (int i=0; i&lt;width+2; i++) { maze[i][0] = maze[i][height+1] = OBSTICLE; } /** * Randomize the maze by putting up arbitray obsticals */ int max_obsticles = (width * height) / 3; for (int i=0; i&lt;max_obsticles; i++) { int x = (int)(Math.random()*width); int y = (int)(Math.random()*height); setValue(x, y, OBSTICLE); } /** * Specify the starting location */ startLoc.width = 0; startLoc.height = 0; setValue(0, 0, (short)0); /** * Specify the goal location */ goalLoc.width = width - 1; goalLoc.height = height - 1; setValue(width - 1, height - 1, GOAL_LOC_VALUE); } synchronized public short getValue(int x, int y) { return maze[x+1][y+1]; } synchronized public void setValue(int x, int y, short value) { maze[x+1][y+1] = value; } public int getWidth() { return width; } public int getHeight() { return height; } } </TEXTAREA><br><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2002-01-19T16:00:00Z MazeBreadthFirstSearch.java 2002-01-19T16:00:00Z 2002-01-19T16:00:00Z <br/><TEXTAREA name="code" class="java" rows="16" cols="100">import javax.swing.*; import java.awt.*; import java.awt.image.*; import java.awt.event.*; /** * Title: MazeBreadthFirstSearch&lt;p&gt; * Description: Demo program for Java AI Programming&lt;p&gt; * Copyright: Copyright (c) Mark Watson, Released under Open Source Artistic License&lt;p&gt; * Company: Mark Watson Associates&lt;p&gt; * @author Mark Watson * @version 1.0 */ public class MazeBreadthFirstSearch extends javax.swing.JFrame { JPanel jPanel1 = new JPanel(); BreadthFirstSearchEngine currentSearchEngine = null; public MazeBreadthFirstSearch() { try { jbInit(); } catch (Exception e) { System.out.println(&quot;GUI initilization error: &quot; + e); } currentSearchEngine = new BreadthFirstSearchEngine(10, 10); repaint(); } public void paint(Graphics g_unused) { if (currentSearchEngine == null) return; Maze maze = currentSearchEngine.getMaze(); int width = maze.getWidth(); int height = maze.getHeight(); System.out.println(&quot;Size of current maze: &quot; + width + &quot; by &quot; + height); Graphics g = jPanel1.getGraphics(); BufferedImage image = new BufferedImage(320, 320, BufferedImage.TYPE_INT_RGB); Graphics g2 = image.getGraphics(); g2.setColor(Color.white); g2.fillRect(0, 0, 320, 320); g2.setColor(Color.black); for (int x=0; x&lt;width; x++) { for (int y=0; y&lt;height; y++) { short val = maze.getValue(x,y); if ( val == Maze.OBSTICLE) { g2.setColor(Color.lightGray); g2.fillRect(6 + x * 28, 3 + y * 29, 29, 30); } else if (val == Maze.START_LOC_VALUE || (x==0 &amp;&amp; y==0)) { g2.setColor(Color.blue); g2.drawString(&quot;S&quot;, 16 + x * 28, 19 + y * 29); } else if (val == Maze.GOAL_LOC_VALUE) { g2.setColor(Color.red); g2.drawString(&quot;G&quot;, 16 + x * 28, 19 + y * 29); } } } // redraw the path in black: g2.setColor(Color.black); Dimension [] path = currentSearchEngine.getPath(); for (int i=1; i&lt; (path.length-1); i++) { int x = path[i].width; int y = path[i].height; short val = maze.getValue(x,y); g2.drawString(&quot;&quot; + (path.length - i), 16 + x * 28, 19 + y * 29); } g.drawImage(image, 30, 40, 320, 320, null); } public static void main(String[] args) { MazeBreadthFirstSearch mazeSearch1 = new MazeBreadthFirstSearch(); } private void jbInit() throws Exception { this.setContentPane(jPanel1); this.setCursor(null); this.setDefaultCloseOperation(3); this.setTitle(&quot;MazeBreadthFirstSearch&quot;); this.getContentPane().setLayout(null); jPanel1.setBackground(Color.white); jPanel1.setDebugGraphicsOptions(DebugGraphics.NONE_OPTION); jPanel1.setDoubleBuffered(false); jPanel1.setRequestFocusEnabled(false); jPanel1.setLayout(null); this.setSize(370, 420); this.setVisible(true); } } </TEXTAREA><br><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2002-01-19T16:00:00Z MazeDepthFirstSearch.java 2002-01-19T16:00:00Z 2002-01-19T16:00:00Z <br/><TEXTAREA name="code" class="java" rows="16" cols="100">import javax.swing.*; import java.awt.*; import java.awt.image.*; import java.awt.event.*; /** * Title: MazeDepthFirstSearch&lt;p&gt; * Description: Demo program for Java AI Programming&lt;p&gt; * Copyright: Copyright (c) Mark Watson, Released under Open Source Artistic License&lt;p&gt; * Company: Mark Watson Associates&lt;p&gt; * @author Mark Watson * @version 1.0 */ public class MazeDepthFirstSearch extends javax.swing.JFrame { JPanel jPanel1 = new JPanel(); DepthFirstSearchEngine currentSearchEngine = null; public MazeDepthFirstSearch() { try { jbInit(); } catch (Exception e) { System.out.println(&quot;GUI initilization error: &quot; + e); } currentSearchEngine = new DepthFirstSearchEngine(10, 10); repaint(); } public void paint(Graphics g_unused) { if (currentSearchEngine == null) return; Maze maze = currentSearchEngine.getMaze(); int width = maze.getWidth(); int height = maze.getHeight(); System.out.println(&quot;Size of current maze: &quot; + width + &quot; by &quot; + height); Graphics g = jPanel1.getGraphics(); BufferedImage image = new BufferedImage(320, 320, BufferedImage.TYPE_INT_RGB); Graphics g2 = image.getGraphics(); g2.setColor(Color.white); g2.fillRect(0, 0, 320, 320); g2.setColor(Color.black); for (int x=0; x&lt;width; x++) { for (int y=0; y&lt;height; y++) { short val = maze.getValue(x,y); if ( val == Maze.OBSTICLE) { g2.setColor(Color.lightGray); g2.fillRect(6 + x * 28, 3 + y * 29, 29, 30); } else if (val == Maze.START_LOC_VALUE || val == 1) { g2.setColor(Color.blue); g2.drawString(&quot;S&quot;, 16 + x * 28, 19 + y * 29); } else if (val == Maze.GOAL_LOC_VALUE) { g2.setColor(Color.red); g2.drawString(&quot;G&quot;, 16 + x * 28, 19 + y * 29); } else if (val &gt; 0) { //g2.setColor(Color.green); //g2.drawString(&quot;&quot; + val, 16 + x * 28, 19 + y * 29); } } } // redraw the path in black: g2.setColor(Color.black); Dimension [] path = currentSearchEngine.getPath(); for (int i=1; i&lt; path.length; i++) { int x = path[i].width; int y = path[i].height; short val = maze.getValue(x,y); g2.drawString(&quot;&quot; + val, 16 + x * 28, 19 + y * 29); } g.drawImage(image, 30, 40, 320, 320, null); } public static void main(String[] args) { MazeDepthFirstSearch mazeSearch1 = new MazeDepthFirstSearch(); } private void jbInit() throws Exception { this.setContentPane(jPanel1); this.setCursor(null); this.setDefaultCloseOperation(3); this.setTitle(&quot;MazeDepthFirstSearch&quot;); this.getContentPane().setLayout(null); jPanel1.setBackground(Color.white); jPanel1.setDebugGraphicsOptions(DebugGraphics.NONE_OPTION); jPanel1.setDoubleBuffered(false); jPanel1.setRequestFocusEnabled(false); jPanel1.setLayout(null); this.setSize(370, 420); this.setVisible(true); } } </TEXTAREA><br><br/><script type="text/javascript"><!--google_ad_client = "pub-9426659565807829";google_ad_slot = "9359905831";google_ad_width = 728;google_ad_height = 15;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script> 2002-01-19T16:00:00Z