Java Draw Line based on doubles (sub-pixel precision)

后端 未结 2 1847
后悔当初
后悔当初 2020-12-17 16:09

I am making a basic Java program and I would like to draw a line using basic swing Graphics.drawLine.

Is there a way to make the two points in terms of doubles so I

2条回答
  •  伪装坚强ぢ
    2020-12-17 16:29

    If you have a refernce to g, which I assume is Graphics object, you should use Java 2D APIs

    Graphics2D g2 = (Graphics2D) g;
    g2.draw(new Line2D.Double(x1, y1, x2, y2));
    

    Javadocs for:

    • Line2D
    • Graphics2D

提交回复
热议问题