private void drawPoint(City city) { graphics.fillOval(city.getCoordinate().getX(), city.getCoordinate().getY(), 16, 12); graphics.drawString( "(" + city.getCoordinate().getX() + "," + city.getCoordinate().getY() + ")", city.getCoordinate().getX(), city.getCoordinate().getY()); }
private void drawPath(Path path) { List<City> solvedCityList = path.getOrderedCityList(); City city1 = null, city2 = null; graphics.setColor(Color.green); if (solvedCityList != null && solvedCityList.size() > 0) { city1 = solvedCityList.get(0); solvedCityList.remove(0); } for (City city : solvedCityList) { city2 = city; int x1, x2, y1, y2; x1 = city1.getCoordinate().getX(); y1 = city1.getCoordinate().getY(); x2 = city2.getCoordinate().getX(); y2 = city2.getCoordinate().getY(); graphics.setColor(Color.green); graphics.drawLine(x1, y1, x2, y2); // String pathLength = city1.getDistance(city2).getValue(); // int xd = (x1+x2)/2; // int yd = (y1+y2)/2; graphics.setColor(Color.BLUE); // graphics.drawString(pathLength, xd, yd); city1 = city2; } }
private void drawCities(List<City> cities) { Color origColor = graphics.getColor(); graphics.setColor(Color.red); int x1, y1; for (City city : cities) { x1 = city.getCoordinate().getX(); y1 = city.getCoordinate().getY(); if (city.isStart() || city.isEnd()) { graphics.fillOval(x1, y1, 8, 4); } else { graphics.drawOval(x1, y1, 8, 4); } graphics.drawString("(" + x1 + "," + y1 + ")", x1, y1); } graphics.setColor(origColor); }
private void drawSolution(List<City> solvedCityList) { City city1 = null, city2 = null; mapPanel.paint(graphics); graphics.setColor(Color.green); if (solvedCityList != null && solvedCityList.size() > 0) { city1 = solvedCityList.get(0); solvedCityList.remove(0); } for (City city : solvedCityList) { city2 = city; int x1, x2, y1, y2; x1 = city1.getCoordinate().getX(); y1 = city1.getCoordinate().getY(); x2 = city2.getCoordinate().getX(); y2 = city2.getCoordinate().getY(); graphics.setColor(Color.green); graphics.drawLine(x1, y1, x2, y2); graphics.setColor(Color.red); if (city1.isStart()) { graphics.fillOval(x1, y1, 16, 12); } else { graphics.drawOval(x1, y1, 16, 12); } graphics.drawString("(" + x1 + "," + y1 + ")", x1, y1); if (city2.isEnd()) { graphics.fillOval(x2, y2, 16, 12); } else { graphics.drawOval(x2, y2, 16, 12); } graphics.drawString("(" + x2 + "," + y2 + ")", x2, y2); String pathLength = city1.getDistance(city2).getValue(); int xd = (x1 + x2) / 2; int yd = (y1 + y2) / 2; graphics.setColor(Color.BLUE); graphics.drawString(pathLength, xd, yd); city1 = city2; } }