go to previous page   go to home page   go to next page highlighting

Answer:

primaryStage.show() asks the system to show the window on the monitor screen. In large programs this is easy to forget. If you run your program, and nothing happens, check that you have called this method.

When you create a Stage object it is not automatically displayed. A large application might create several Stage objects, but might only display one of them at a time.


The Program Explained

Stage in memory rendered on the screen

In this picture, the pink clouds represent classes. Here is the program again:

import javafx.application.*;
import javafx.stage.*;
 
public class TestFX extends Application
{
  public void start( Stage primaryStage )
  {
    primaryStage.show();
  }

  // Not needed for most systems
  public static void main( String[] args )
  {
    launch();
  } 
}

Explanation of the program:

  1. Import the JavaFX packages for Application and Stage.
  2. Define a class that extends Application.
  3. Define a start() method which overrides the abstract method in the Application class
  4. The runtime system automatically creates a Stage and calls the start() with a reference to it.
  5. Various methods of Stage may be invoked.
  6. Call primaryStage.show() to put the window on the screen.

QUESTION 5:

Must the parameter for start() be named primaryStage ?


go to previous page   go to home page   go to next page