DEV Community

Cover image for CREATING A BUTTON USING JAVAFX
betpido
betpido

Posted on

CREATING A BUTTON USING JAVAFX

JAVAFX is the language that is used to create windows and visual elements for java applications

To use JAVAFX to create a java window,

  1. make sure your Java class extends "Application"
    example: public class JavaFX extends Application{}

  2. implement the 'start()' method of the Application class
    example: @Override
    public void start(Stage primaryStage) {}

  3. Inside the start() method, a button and call it 'btOK'
    example: Button btOK = new Button();
    Now give the button a text 'Ih"
    example: btOK.setText("lh");

  4. To show the button the window, create a "SCENE" and put the button on the scene.
    example: Scene scene = new Scene(btOK,200,250);
    defined as 'new Scene('button name', SCENE width in pixels, SCENE height in pixels)

  5. To display the SCENE on the screen for the user, place the SCENE on a STAGE.
    example: primaryStage.setScene(scene);

set the title of the STAGE: primaryStage.setTitle("MyJavaFX");

show the stage: primaryStage.show();

Finally, call the 'launch(args)' method. It is needed to test your application.

DONE.

Top comments (0)