public static void drawLine(int color, int x1, int y1, int x2, int y2, Graphics g) { if (y2 < y1) { int top = y2; y2 = y1; y1 = top; } if (x2 < x1) { int left = x2; x1 = x2; x2 = x1; x1 = left; } if (x1 == x2 || y1 == y2) { int width = x2 - x1; if (width == 0) { width = 1; } int height = y2 - y1; if (height == 0) { height = 1; } int[] rgb = new int[Math.max(width, height)]; for (int i = 0; i < rgb.length; i++) { rgb[i] = color; } g.drawRGB(rgb, 0, width, x1, y1, width, height, true); } else { g.setColor(color); g.drawLine(x1, y1, x2, y2); } }