0

I want to animate sorting algorithms within a canvas in a javafx app. Frstly I have everything within a Border Panel. In the Left section I have a Scroll Pane with a Vbox within that holding the menu buttons for selecting the specific algorithm to animate. In the Center section I have a Vbox with a Canvas in it that I want to animate the visualizations in. My question is how to set the scene to animate the visualization within the Canvas on menu button click? Say I have a BubbleSort class that I want to animate in the Canvas. Would I accomplish this through Main or a controller? My current Main is below:

    public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
        Parent root = FXMLLoader.load(getClass().getResource("views/HomeView.fxml"));
        primaryStage.setTitle("Hello World");
        primaryStage.setScene(new Scene(root, 300, 275));
        root.getStylesheets().add("app/styling/css/styles.css");
        primaryStage.show();
    }


    public static void main(String[] args) {
        launch(args);
    }
}

1 Answer 1

0

In a JavaFX Application, the main method's purpose (actually the start method) is only to initialize the FXML and other major pieces. The bulk of your UI logic should be contained in your Controller class.

First, you need to define an action handler in your controller. There are many tutorials available online, and it is a fairly simple task in Scenebuilder. Google is your best friend here.

For animations, since JavaFX doesn't allow its displayed contents to be modified by threads other than the JavaFX Application Thread, in which the main application runs, you will have to use classes from the javafx.animationpackage. See Creating Transitions and Timeline Animation in JavaFX.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.