一、绘制一个窗口
package sample;
import javafx.application.Application;
import javafx.stage.Stage;
public class Main extends Application {
public static void main(String[] args)
{
// Launch the application.
launch(args);
}
@Override
public void start(Stage primaryStage)
{
// Set the stage title.
primaryStage.setTitle("My First GUI Application");
// Show the window.
primaryStage.show();
}
}
Line 1 imports the
Application
class, which is in the
JavaFX.application
package.
Line 2 imports the
Stage
class, which is in the
JavaFX.stage
package. (You will see this class used in the
start
method.)
The declaration for the
MyFirstGUI
class begins in line 8. Notice that it extends the
Application
class.
The
main
method appears in lines 10 through 14. The
main
method does only one thing: it calls the
launch
method in line 13. The
launch
method, which is inherited from the
Application
class, does a number of setup operations, including the following:
It creates a
Stage
object that will be the application’s window.
It calls the
start
method, passing a reference to the
Stage
object as an argument.
The
start
method appears in lines 17 through 24. This is the entry point for the applicati