import javafx.application.Application;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String[] args) {
System.out.println("main()-" + Thread.currentThread().getName());
launch(args);
}
@Override
public void init() throws Exception {
System.out.println("init()-" + Thread.currentThread().getName());
}
@Override
public void start(Stage primaryStage) throws Exception {
System.out.println("start()-" + Thread.currentThread().getName());
primaryStage.setTitle("这是第一个窗口");
primaryStage.show();
}
@Override
public void stop() throws Exception {
System.out.println("stop()-" + Thread.currentThread().getName());
}
}
Application中包括init(),start(Stage stage)和stop()方法。执行上面程序可以得到如下结果:
main()-main
init()-JavaFX-Launcher
start()-JavaFX Application Thread
stop()-JavaFX Application Thread
stop方法在关闭窗口时才会被调用