• JavaFX runtime creates several threads. At different stages in the application, threads are used to perform different tasks.
  • The JavaFX runtime creates,two threads, among other threads,
    JavaFX Application Thread
  • The launch() method of the Application class, is called only once; and it invokes the following threads.
  • JavaFX runtime calls the following methods of the specified JavaFX Application class in order:
    The no-args constructor
    The init() method : JavaFX Launcher Thread calls the init().; this thread can't have a Stage or Scene
    The start() method:: This thread contains Stage and Scene
    The stop() method
  • EventHandler in  a class;
  • Platform.exit()
Code :

package javafxtemplate1;

import javafx.application.Application;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.stage.Stage;

* @author Manas9
public class JavaFXTemplate1 extends Application {
public String str1;
public void init() {
str1 = Thread.currentThread().getName();
//System.out.println("init() method: " + name);
public void start(Stage primaryStage) {
Group groot = new Group();
Button btn1 = new Button("Title Button1");
Button btn2 = new Button("Exit Platform");
Label label1 = new Label("Label");
//Lambda expression  class
btn1.setOnAction((ActionEvent e) -> {
// System.out.println(str1+ "Hello World");
primaryStage.setTitle("Hello World");
btn2.setOnAction(new DemoEventHandler1(){ });
groot.getChildren().addAll(btn1, label1, btn2);
Scene scene = new Scene(groot, 200, 150);
public static void main(String[] args) {
class DemoEventHandler1 implements EventHandler<ActionEvent>{

public void handle(ActionEvent event) {


Runtime Views: (Click on Exit Platform to close the display stage.

Title Button

Exit Platform will close the application.