public void paint(Graphics graphics) {
		// create an offscreen buffer to render the map

		if (buffer == null) {
			buffer = new BufferedImage(600, 600, BufferedImage.TYPE_INT_ARGB);
		}
		Graphics g = buffer.getGraphics();

		g.clearRect(0, 0, 600, 600);
		g.translate(50, 50);

		// cycle through the tiles in the map drawing the appropriate

		// image for the terrain and units where appropriate

		for (int x = 0; x < map.getWidthInTiles(); x++) {
			for (int y = 0; y < map.getHeightInTiles(); y++) {
				g.drawImage(tiles[map.getTerrain(x, y)], x * 16, y * 16, null);
				if (map.getUnit(x, y) != 0) {
					g.drawImage(tiles[map.getUnit(x, y)], x * 16, y * 16, null);
				} else {
					if (path != null) {
						if (path.contains(x, y)) {
							g.setColor(Color.blue);
							g.fillRect((x * 16) + 4, (y * 16) + 4, 7, 7);
						}
					}
				}
			}
		}

		// if a unit is selected then draw a box around it

		if (selectedx != -1) {
			g.setColor(Color.black);
			g.drawRect(selectedx * 16, selectedy * 16, 15, 15);
			g.drawRect((selectedx * 16) - 2, (selectedy * 16) - 2, 19, 19);
			g.setColor(Color.white);
			g.drawRect((selectedx * 16) - 1, (selectedy * 16) - 1, 17, 17);
		}

		// finally draw the buffer to the real graphics context in one

		// atomic action

		graphics.drawImage(buffer, 0, 0, null);
	}