(Im assuming you might want to use javafx)
First you need to create a canvas object and a graphics object, add an event handler to it that maybe passes the necessary parameter to handle the event. then override the handle method for it to stroke a line from x,y to x,y. (maybe a stroke method). You also have to previously set the scene to display and the stroke and so and so.