package com.github.zdziszkee.maze; import com.github.zdziszkee.maze.generators.DefaultGenerator; import com.github.zdziszkee.maze.model.Maze; import com.github.zdziszkee.maze.model.MazeCell; import com.github.zdziszkee.maze.model.MazeCellType; import javafx.application.Application; import javafx.beans.binding.Bindings; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Group; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.layout.*; import javafx.scene.paint.Color; import javafx.scene.shape.Rectangle; import javafx.scene.transform.Scale; import javafx.stage.Stage; import java.util.concurrent.ThreadLocalRandom; public class MazeApp extends Application { @Override public void start(Stage primaryStage) { // Create a Pane to hold the rectangle Pane pane = new Pane(); // Create a Rectangle with initial size Rectangle rectangle = new Rectangle(100, 100, 200, 150); rectangle.setFill(Color.BLUE); // Add the rectangle to the pane pane.getChildren().add(rectangle); // Create a Scene and add the pane to it Scene scene = new Scene(pane, 400, 300); // Add ChangeListeners to the scene's width and height properties ChangeListener sizeListener = new ChangeListener() { @Override public void changed(ObservableValue observable, Number oldValue, Number newValue) { adjustRectangleSize(scene, rectangle); } }; scene.widthProperty().addListener(sizeListener); scene.heightProperty().addListener(sizeListener); // Set the title of the Stage primaryStage.setTitle("Scalable Rectangle App"); // Add the scene to the stage primaryStage.setScene(scene); // Show the stage primaryStage.show(); } private void adjustRectangleSize(Scene scene, Rectangle rectangle) { double aspectRatio = 200.0 / 150.0; // Aspect ratio of the rectangle double newWidth = scene.getWidth() * 0.5; double newHeight = scene.getHeight() * 0.5; if (newWidth / aspectRatio > newHeight) { newWidth = newHeight * aspectRatio; } else { newHeight = newWidth / aspectRatio; } rectangle.setWidth(newWidth); rectangle.setHeight(newHeight); // Center the rectangle rectangle.setX((scene.getWidth() - newWidth) / 2); rectangle.setY((scene.getHeight() - newHeight) / 2); } public static void main(String[] args) { launch(args); } }