java draw line as the mouse is moved

后端 未结 3 853
面向向阳花
面向向阳花 2020-12-10 00:00

I would like to add a feature to my application which allows the user to draw a straight line by clicking the mouse at the start location and releasing it at the end locatio

3条回答
  •  一个人的身影
    2020-12-10 00:52

    The MouseListener interface is your friend for this. You can just implement mousePressed and mouseReleased functions. The MouseListener interface has the following methods that you can play around with:

    public void mouseEntered(MouseEvent mouse){ }   
    public void mouseExited(MouseEvent mouse){ }
    public void mousePressed(MouseEvent mouse){ }
    public void mouseReleased(MouseEvent mouse){ }
    

提交回复
热议问题