Java Reference
In-Depth Information
object. This is the stage provided by the run-time system and is the primary stage. Notice
that this method is abstract. Thus, it must be overridden by your application.
When your application is terminated, the stop( ) method is called. It is here that you can
handle any cleanup or shutdown chores. In cases in which no such actions are needed, an
empty, default version is provided.
Launching a JavaFX Application
To start a free-standing JavaFX application, you must call the launch( ) method defined by
Application . It has two forms. Here is the one used in this chapter:
public static void launch(String … args )
Here, args is a possibly empty list of strings that typically specify command-line argu-
ments. When called, launch( ) causes the application to be constructed, followed by calls to
init( ) and start( ) . The launch( ) method will not return until after the application has ter-
minated. This version of launch( ) starts the subclass of Application from which launch(
) is called. The second form of launch( ) lets you specify a class other than the enclosing
class to start.
Before moving on, it is necessary to make an important point: JavaFX applications that
have been packaged by using the javafxpackager tool (or its equivalent in an IDE) do not
need to include a call to launch( ) . However, its inclusion often simplifies the test/debug
cycle, and it lets you use the program without creating a JAR file. Thus, it is included in
the programs in this chapter.
A JavaFX Application Skeleton
All JavaFX applications share the same basic skeleton. Therefore, before looking at any
more JavaFX features, it will be useful to see what that skeleton looks like. In addition
to showing the general form of a JavaFX application, the skeleton also illustrates how to
launch the application and demonstrates when the life-cycle methods are called. A message
noting when each life-cycle method is called is displayed on the console. The complete
skeleton is shown here:
Search WWH ::




Custom Search