代码如下
package com.laolang.keditor;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import lombok.extern.slf4j.Slf4j;
/**
* @author khlbat
* @version 1.0
* @date 2021/3/12
*/
@Slf4j
public class KEditor extends Application {
public static void main(String[] args) {
log.info("main : " + Thread.currentThread().getName());
launch(args);
}
@Override
public void init() throws Exception {
log.info("init : " + Thread.currentThread().getName());
// 默认什么都不做
}
@Override
public void start(Stage primaryStage) throws Exception {
log.info("start : " + Thread.currentThread().getName());
Parent root = FXMLLoader.load(getClass().getClassLoader().getResource("main.fxml"));
Scene scene = new Scene(root,800,600);
primaryStage.setTitle("第一个窗口");
primaryStage.setScene(scene);
primaryStage.show();
}
@Override
public void stop() throws Exception {
log.info("stop : " + Thread.currentThread().getName());
// 默认什么都不做
}
}
日志如下
2021-03-22 15:16:27.478 [main] INFO com.laolang.keditor.KEditor - main : main
2021-03-22 15:16:27.487 [JavaFX-Launcher] INFO com.laolang.keditor.KEditor - init : JavaFX-Launcher
2021-03-22 15:16:27.512 [JavaFX Application Thread] INFO com.laolang.keditor.KEditor - start : JavaFX Application Thread
2021-03-22 15:16:31.522 [JavaFX Application Thread] INFO com.laolang.keditor.KEditor - stop : JavaFX Application Thread
其中 JavaFX Application
即为UI线程