I\'m wondering if there\'s a funciton in Java that can draw a line from the coordinates (x1, x2) to (y1, y2)?
What I want is to do something like this:
I built a whole class of methods to draw points, lines, rectangles, circles, etc. I designed it to treat the window as a piece of graph paper where the origin doesn't have to be at the top left and the y values increase as you go up. Here's how I draw lines:
public static void drawLine (double x1, double y1, double x2, double y2)
{
((Graphics2D)g).draw(new Line2D.Double(x0+x1*scale, y0-y1*scale, x0+x2*scale, y0-y2*scale));
}
In the example above, (x0, y0) represents the origin in screen coordinates and scale is a scaling factor. The input parameters are to be supplied as graph coordinates, not screen coordinates. There is no repaint() being called. You can save that til you've drawn all the lines you need.
It occurs to me that someone might not want to think in terms of graph paper:
((Graphics2D)g).draw(new Line2D.Double(x1, y1, x2, y2));
Notice the use of Graphics2D. This allows us to draw a Line2D object using doubles instead of ints. Besides other shapes, my class has support for 3D perspective drawing and several convenience methods (like drawing a circle centered at a certain point given a radius.) If anyone is interested, I would be happy to share more of this class.