--main clasd-
package javafxtemplate1;
import java.io.IOException;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;

public class JavaFXTemplate1 extends Application {

public void start(Stage primaryStage) throws IOException {
Parent root = FXMLLoader.load(getClass().getResource("JavaFXMLDoc1.fxml"));
//Scene scene = new Scene(root);

//Group root = new Group();
Scene scene = new Scene(root, 450,300);
primaryStage.setTitle("FXML BorderPane::Label, Button");

public static void main(String[] args) {


<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.net.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.control.Label?>

<BorderPane id="BorderPane" prefHeight="400.0" prefWidth="600.0" styleClass="mainFxmlClass" xmlns:fx="http://javafx.com/fxml/1" fx:controller="javafxtemplate1.JavaFXMLDoc1Controller">
<URL value="@javafxmldoc1.css"/>
<Button layoutX="126" layoutY="90" text="Start!" onAction="#startTask" fx:id="button1" />

<Label layoutX="126" layoutY="120" minHeight="16" minWidth="69" fx:id="label1" />
<Button layoutX="146" layoutY="190" text="Exit!" onAction="#endTask" fx:id="button2" />

* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
package javafxtemplate1;

import java.net.URL;
import java.util.ResourceBundle;
import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.stage.Stage;

public class JavaFXMLDoc1Controller implements Initializable {

* Initializes the controller class.
private Label label1, label2;
private Stage primaryStage;
private void startTask(ActionEvent event) {
//System.out.println("You clicked me!");
label1.setText("Hello World!");

public void initialize(URL url, ResourceBundle rb) {
//label2.setText("Initialized ");


private void endTask(ActionEvent event) {
//System.out.println("You clicked me!");



Start event:

Exit event, will close the application.