xiaozhuai
4/13/2017 - 8:47 AM

Demo of JavaFx with GUI application

Demo of JavaFx with GUI application

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

<?import javafx.scene.control.Button?>
<?import javafx.scene.layout.Pane?>

<Pane prefHeight="540" prefWidth="960" xmlns="http://javafx.com/javafx/8.0.112" xmlns:fx="http://javafx.com/fxml/1" fx:controller="sample.Controller">
    <Button fx:id="mButton" onAction="#onButtonClicked" text="Hello">

    </Button>
</Pane>
package sample;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;

import java.io.IOException;


public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws IOException {
        Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
        primaryStage.setTitle("Hello World");
        primaryStage.setScene(new Scene(root));
        primaryStage.show();
    }


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

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;



public class Controller{

    public Controller(){
        System.out.println("aaa");
    }

    @FXML
    private Button mButton;

    @FXML
    private void onButtonClicked(ActionEvent event){
        mButton.setText("World");
    }
}