How to draw lines in Java

前端 未结 10 2043
梦毁少年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:19

    In your class you should have:

    public void paint(Graphics g){
       g.drawLine(x1, y1, x2, y2);
    }
    

    Then in code if there is needed you will change x1, y1, x2, y2 and call repaint();.

提交回复
热议问题