56 lines
1.7 KiB
Java
56 lines
1.7 KiB
Java
package sample;
|
|
|
|
import javafx.application.Application;
|
|
import javafx.event.EventHandler;
|
|
import javafx.fxml.FXMLLoader;
|
|
import javafx.scene.Parent;
|
|
import javafx.scene.Scene;
|
|
import javafx.scene.input.MouseEvent;
|
|
import javafx.stage.Stage;
|
|
import javafx.stage.StageStyle;
|
|
|
|
public class Main extends Application {
|
|
|
|
private double xOffset = 0;
|
|
private double yOffset = 0;
|
|
|
|
volatile double[] posOrigin = {0, 0};
|
|
|
|
@Override
|
|
public void start(Stage primaryStage) throws Exception{
|
|
primaryStage.initStyle(StageStyle.UNDECORATED);
|
|
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
|
|
primaryStage.setTitle("Team-Avion Launcher [WIP]");
|
|
primaryStage.setScene(new Scene(root, 900, 500));
|
|
primaryStage.show();
|
|
primaryStage.maximizedProperty().addListener((observable, oldValue, newValue) -> {
|
|
if (newValue) {
|
|
primaryStage.setMaximized(false);
|
|
}
|
|
});
|
|
root.lookup("#exit").setOnMouseClicked(event -> primaryStage.close());
|
|
|
|
// Drag
|
|
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);
|
|
}
|
|
});
|
|
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
launch(args);
|
|
}
|
|
}
|