ANSWER 22
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
public class SquareButton extends Application {
private static final int SQUARE_SIZE = 10;
private static final int PANE_WIDTH = 500;
private static final int PANE_HEIGHT = 500;
private static final int MOVE_AMOUNT = 20;
private Rectangle square;
public void start(Stage primaryStage) {
Pane pane = new Pane();
pane.setPrefSize(PANE_WIDTH, PANE_HEIGHT);
pane.setStyle("-fx-border-color: black; -fx-border-width: 1px;");
pane.setPadding(new Insets(10));
square = new Rectangle(SQUARE_SIZE, SQUARE_SIZE, Color.RED);
square.setX(0);
square.setY(PANE_HEIGHT / 2 - SQUARE_SIZE / 2);
Button moveButton = new Button("Move Right");
moveButton.setOnAction(e -> moveSquare());
pane.getChildren().addAll(square, moveButton);
Scene scene = new Scene(pane);
primaryStage.setTitle("Square Button");
primaryStage.setScene(scene);
primaryStage.show();
private void moveSquare() {
double newX = square.getX() + MOVE_AMOUNT;
if (newX + SQUARE_SIZE <= PANE_WIDTH) {
square.setX(newX);
public static void main(String[] args) {
launch(args);