import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.Button;
import javafx.stage.Stage;

public class LeftRightButton extends Application {
    private int x = 20;
    private Canvas canvas;

    public void start(Stage stage) {
        stage.setTitle("ƒOƒ‰ƒt");

        canvas = new Canvas(200, 70);
        GraphicsContext gc = canvas.getGraphicsContext2D();
        paint(gc);

        Button lBtn = new Button("Left");
        Button rBtn = new Button("Right");

        lBtn.setOnAction(e -> {
            x -= 10;
            paint(canvas.getGraphicsContext2D());
        });

        rBtn.setOnAction(e -> {
            x += 10;
            paint(canvas.getGraphicsContext2D());
        });

        HBox top = new HBox();
        top.setAlignment(Pos.BASELINE_CENTER);
        top.getChildren().addAll(lBtn, rBtn);
        VBox root = new VBox();
        root.setAlignment(Pos.CENTER);
        root.getChildren().addAll(top, canvas);
        Scene scene = new Scene(root);
        stage.setScene(scene);
        stage.show();
    }

    private void paint(GraphicsContext gc) {
        gc.clearRect(0, 0, canvas.getWidth(), canvas.getHeight());
        gc.fillText("HELLO WORLD!", x, 55);
    }

    public static void main(String... args) {
        launch(args);
    }
}
