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

Answer:

    double radius = 100.0, 
           yCenter = radius*3/2, 
           xCenter = radius*3/2 ;
    Circle circle = new Circle( xCenter, yCenter, radius); 
    circle.setFill(  Color.YELLOW );  
    circle.setStroke( Color.DARKCYAN );

    Pane pane =   new Pane( circle );   
    Scene scene = new Scene( pane, radius*3, radius*3, Color.GHOSTWHITE ); 

This puts the circle centered in the window with a margin of half the radius. You could squeeze the circle into a smaller window:

    double radius = 100.0, 
           yCenter = radius*5/4, 
           xCenter = radius*5/4 ;
    Circle circle = new Circle( xCenter, yCenter, radius); 
    circle.setFill(  Color.YELLOW );  
    circle.setStroke( Color.DARKCYAN );

    Pane pane =   new Pane( circle );   
    Scene scene = new Scene( pane, radius*5/2, radius*5/2, Color.GHOSTWHITE ); 

Scene Graph

Part of the job of start() is to create a scene graph. This is a data structure that organizes the Nodes of the Application. Nodes are the Shapes, GUI controls, Panes and several other types of objects. We have already seen Circle which is a kind of Shape.

Here (again) is the code that creates the scene graph for the previous program:

import javafx.application.*;  
import javafx.stage.*;        
import javafx.scene.Scene;  
import javafx.scene.Group;  
import javafx.scene.layout.*;  
import javafx.scene.shape.*; 
import javafx.scene.paint.*;  

public class CircleDarker extends Application  
{
  public void start( Stage primaryStage ) 
  {
    Color  myFill    = new Color( 0.9, 0.7, 0.9, 1.0 );
    
    double rad = 50.0, yCenter = rad*3/2, xCenter = rad*3/2, shift = rad ;
    Circle circleA = new Circle( xCenter, yCenter, rad); 
    circleA.setFill( myFill );   
    circleA.setStroke( Color.PURPLE );
 
    xCenter += shift;
    myFill = myFill.darker();
    Circle circleB = new Circle( xCenter, yCenter, rad); 
    circleB.setFill( myFill );   
    circleB.setStroke( Color.PURPLE );
 
    xCenter += shift;
    myFill = myFill.darker();
    Circle circleC = new Circle( xCenter, yCenter, rad); 
    circleC.setFill( myFill );   
    circleC.setStroke( Color.PURPLE );
    
    Pane pane =   new Pane( circleA, circleB, circleC );   
    Scene scene = new Scene( pane, rad*5, rad*3, Color.AQUA.brighter() ); 
    
    primaryStage.setTitle("Darker Circles");
    primaryStage.setScene( scene );   
    primaryStage.show();
  }
}

Here is the scene graph that it creates:

Scene Graph: root with three child nodes

In this scene graph, the root node is a Pane referenced by the variable pane. The three Circles are children of the root node.

In general (in more complex scenes), a node in the graph has one parent and may have several children. No node has more than one parent. A root is the node that has no parent. (You may recognize this as a tree data structure.)

The Java run time system uses the information the the scene graph to draw the window on the monitor screen.


QUESTION 14:

(Thought Question: ) Could the same object occur two or more times a scene graph?


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