Java Reference
In-Depth Information
By the way, you can detect when there is an external request to close the Stage by using the onCloseRequest
event handler as shown in the following code snippet from Listing 2-1.
stage.setOnCloseRequest((WindowEvent we) -> {
System.out.println("Stage is closing");
});
To see this in action, run the application without any arguments so that it has the appearance of Figure 2-2 shown
previously, and then click the close button on the decoration of the window.
the onCloseRequest event handler is only called when there is an external request to close the window. this is
why the “stage is closing” message doesn't appear in this example when you click the button labeled “close( )”.
Tip
Making a Scene
Continuing on with our theater metaphor for creating JavaFX applications, we now discuss putting a Scene on the
Stage . The Scene , as you recall, is the place in which the actors and props (nodes) visually interact with each other
and the audience (the users of your program).
Using the Scene Class: The OnTheScene Example
As with the Stage class, we're going to use a contrived example application to demonstrate and teach the details of the
available capabilities in the Scene class. See Figure 2-6 for a screenshot of the OnTheScene program.
Figure 2-6. The OnTheScene program when first invoked
Go ahead and run the OnTheScene program, putting it through its paces as instructed in the following exercise.
We follow up with a walkthrough of the code so that you can associate the behavior with the code behind it.
 
 
Search WWH ::




Custom Search