Extending the Graphics class with drawLine (double, double, double, double)

Problem: // where the story begins The drawLine (int, int, int, int) method in the Graphics type is not applicable for arguments (double, double, double, double)

g.drawLine ((int) 10 * xi, (int) 30 * yi, (int) 90 * xi, (int) 30 * yi);
// where xi is the width of the Scale and yi is the heightScale

as you can see he's crappy

Actual prototype:
public abstract void drawLine (int x1, int y1, int x2, int y2)
Draws a line, using the current color, between the points (x1, y1) and (x2, y2) in this coordinate system of the graphics context.

What I would like to do:

g.drawLine (double x1, double y1, double x2, double y2);

or

g.drawLine(int x1, int y1, int x2, int y2, double widthScale, double heightScale);

.

+3
2

"" , , , Swing Graphics . : MyGraphics ?

, Line2D, Line2D.Double, Graphics2D. Graphics2D Graphics. Graphics, , JComponents BufferedImages. , , .



, . , , ints , . - , , .

+4

Graphics, , , :

static void drawLine(Graphics g, double x1, double y1, double x2, double y2) {
    g.drawLine(
        (int)Math.round(x1), (int)Math.round(y1),
        (int)Math.round(x2), (int)Math.round(y2));
}

, g.drawLine((int)10*xi, (int)30*yi, (int)90*xi, (int)30*yi); , , , . , (int)10*xi 10 int, xi, . (An int, double, .) , : (int)(10*xi), , - .

+3

All Articles