Got the drag thingto work
This commit is contained in:
parent
e1210440f4
commit
d1a1ce0511
@ -1,15 +1,19 @@
|
|||||||
package sample;
|
package sample;
|
||||||
|
|
||||||
import javafx.application.Application;
|
import javafx.application.Application;
|
||||||
|
import javafx.event.EventHandler;
|
||||||
import javafx.fxml.FXMLLoader;
|
import javafx.fxml.FXMLLoader;
|
||||||
import javafx.scene.Node;
|
|
||||||
import javafx.scene.Parent;
|
import javafx.scene.Parent;
|
||||||
import javafx.scene.Scene;
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.input.MouseEvent;
|
||||||
import javafx.stage.Stage;
|
import javafx.stage.Stage;
|
||||||
import javafx.stage.StageStyle;
|
import javafx.stage.StageStyle;
|
||||||
|
|
||||||
public class Main extends Application {
|
public class Main extends Application {
|
||||||
|
|
||||||
|
private double xOffset = 0;
|
||||||
|
private double yOffset = 0;
|
||||||
|
|
||||||
volatile double[] posOrigin = {0, 0};
|
volatile double[] posOrigin = {0, 0};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -26,8 +30,19 @@ public class Main extends Application {
|
|||||||
root.lookup("#exit").setOnMouseClicked(event -> primaryStage.close());
|
root.lookup("#exit").setOnMouseClicked(event -> primaryStage.close());
|
||||||
|
|
||||||
// Drag
|
// Drag
|
||||||
root.lookup("#rectangle").setOnMouseDragged(event -> {
|
root.lookup("#rectangle").setOnMousePressed(new EventHandler<MouseEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(MouseEvent event) {
|
||||||
|
xOffset = event.getSceneX();
|
||||||
|
yOffset = event.getSceneY();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
root.lookup("#rectangle").setOnMouseDragged(new EventHandler<MouseEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(MouseEvent event) {
|
||||||
|
primaryStage.setX(event.getScreenX() - xOffset);
|
||||||
|
primaryStage.setY(event.getScreenY() - yOffset);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user