javafx使用fxml配置实现的小程序案例

下面是一个使用FXML配置的JavaFX小程序示例:

Main.java:

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {
        FXMLLoader loader = new FXMLLoader(getClass().getResource("sample.fxml"));
        AnchorPane root = loader.load();
        primaryStage.setScene(new Scene(root));
        primaryStage.show();
    }

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

SampleController.java:

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.Label;

public class SampleController {

    @FXML
    private Button button;

    @FXML
    private Label label;

    @FXML
    publi

你可能感兴趣的:(JavaFX专区,javafx,小程序,apache,javafx)