JavaFX Application Life Cycle
/**************************************************
* Author: Morrison
* Date: 15 Oct 2020
**************************************************/
import javafx.application.Application;
import javafx.application.Platform;
import javafx.stage.Stage;
import javafx.scene.Scene;
public class App extends Application
{
public App()
{
}
@Override
public void init()
{
}
@Override
public void start(Stage primary)
{
primary.show();
}
@Override
public void stop()
{
}
}
Life Cycle
- The constructor executes and returns. Use this to initialize all state variables.
init
executes and returns. Use this to do anything needed for your app to run.start
is called. This is the main loop of your application. It all runs in the JavaFX Application thread. All "live" activity must occur within this thread. AllScene
s andStage
s must be created here. This function returns under these cirucmstances.- The user hits the go-away button on the last stage and closes the app.
- A widget, such as a button or menu item tells the app to quit
System.exit()
orPlatform.exit()
is called.
- If
System.exit()
is called, the app quits dead in its tracks (bad). IfPlatform.exit()
is called or the go-away button on the last window is hit,stop()
is called. Since this method is abstract, it must be implemented by any JavaFX appliction. - Execution terminates when
stop()
returns. - The OS cleans up and reallocates the app's memory.
Essential Anatomy Lesson These are the basic parts
of an Application
.
Stage
Scene
- Widgets
- Parents
- Scene Graph