How to draw lines in Java

前端 未结 10 2044
梦毁少年i
梦毁少年i 2020-11-30 02:42

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:



        
10条回答
  •  爱一瞬间的悲伤
    2020-11-30 03:18

    To give you some idea:

    public void paint(Graphics g) {
       drawCoordinates(g);
    }
    
    private void drawCoordinates(Graphics g) {
    
      // get width & height here (w,h)
    
      // define grid width (dh, dv)
    
      for (int x = 0; i < w; i += dh) {
        g.drawLine(x, 0, x, h);
      }
      for (int y = 0; j < h; j += dv) {
          g.drawLine(0, y, w, y);
      }
    }
    

提交回复
热议问题