java - how to draw line with two images using mouse and also how to drag this line with images using javafx? -


i trying draw line between images using mouse when drag, line nor dragged.

public class line1 extends application {     final image image1=new image("image/mme.png");      final image image2=new image("image/hss.png");      final imageview i1=new imageview();      final imageview i2=new imageview();         line line;              @override      public void start(stage primarystage) throws exception {           final borderpane root = new borderpane();           i1.setimage(image1);           i1.setlayoutx(200);           i1.setlayouty(300);           i2.setimage(image2);           i2.setlayoutx(50);           i2.setlayouty(50);           i1.setcursor(cursor.crosshair);            root.getchildren().addall(i1,i2);          root.setonmousepressed(new eventhandler<mouseevent>() {              public void handle(mouseevent event) {                   double x = event.getx();                   double y = event.gety();                   line = new line(x, y, x, y);                   root.getchildren().add(line);                                }         });         root.setonmousedragged(new eventhandler<mouseevent>() {              public void handle(mouseevent event) {                       line.setendx(event.getx());                        line.setendy(event.gety());                    }         });         i1.setonmousedragged(new eventhandler<mouseevent>() {              public void handle(mouseevent event) {                  line.setstartx(event.getscreenx());                  line.setstarty(event.getscreeny());                      line.setendx(i2.getlayoutx());                  line.setendy(i2.getlayouty());                  i1.setlayoutx(event.getscreenx());                  i1.setlayouty(event.getscreeny());                  root.getchildren().add(line);              }              });             primarystage.setscene(new scene(root, 1350, 850));           primarystage.show();      }           public static void main(string[] args) {launch(args);} } 


Comments