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

Answer:

public void start( Stage primaryStage )
{
  double width = 300.0, height = 200.0;
  
  double centerX = width/2; 
  double centerY = height/2; 
  double radiusX = width/2;
  double radiusY = height/2;
  
  Ellipse ellipse = new Ellipse( centerX,  centerY,  radiusX,  radiusY );
  ellipse.setFill( Color.AQUA );
  
  Pane pane = new Pane( ellipse );

  Scene scene = new Scene( pane, width, height, Color.CORNSILK );
  
  primaryStage.setTitle("Bounding Box");
  primaryStage.setScene( scene );
  primaryStage.show();
}

Arc

One Arc

An Arc is part of an Ellipse. In the picture, the Arc is drawn in red against the Ellipse that it is part of. Here is the program:


import javafx.stage.*;
import javafx.scene.Scene;  
import javafx.scene.shape.*;
import javafx.scene.paint.*;
import javafx.scene.layout.*; 
  
public class ArcSimple extends Application
{
  public void start( Stage primaryStage )
  {
    final double width = 400.0, height = 300.0;
    double centerX, centerY;  // center of ellipse and arc
    double radiusX, radiusY;  // radii of ellipse and arc
    double startAngle = 15.0; // angle to start drawing the arc
    double length = 90.0;     // number of degrees to draw
    
    centerX = width/2; centerY=height/2; 
    radiusX = width*0.4; radiusY=width*0.3;
    Ellipse ellipse = new Ellipse( centerX,  centerY,  radiusX,  radiusY );
    ellipse.setFill( Color.IVORY );
    
    Arc arc = new Arc( centerX,  centerY,  radiusX,  radiusY, startAngle, length );
    arc.setFill( Color.TRANSPARENT );
    arc.setStroke( Color.RED );
    arc.setType( ArcType.ROUND ); // Three types of Arc can go here
    arc.setStrokeWidth( 2.0 );
 
    Pane pane = new Pane( ellipse, arc );
    Scene scene = new Scene( pane, width, height, Color.LIGHTGREY );
    
    primaryStage.setTitle("Arc and its Ellipse");
    primaryStage.setScene( scene );
    primaryStage.show();
  }
}

A constructor for Arc is

Arc(double centerX, double centerY, double radiusX, double radiusY, double startAngle, double length)

The first four parameters define the Ellipse the Arc is part of. The last two parameters define what part of the Ellipse to use. Note that these are measured in degrees counter-clockwise starting from the X axis.

  1. centerX       // the X coordinate of the center of the ellipse
  2. centerY       // the Y coordinate of the center of the ellipse
  3. radiusX       // the radius along the X axis of the ellipse
  4. radiusY       // the radius along the Y axis of the ellipse
  5. startAngle     // the angle in degrees for the start of the arc
  6. length       // how many degrees of the arc to draw

Oracle Documentation for Arc.


Arc Parameters

QUESTION 5:

Pie Slice

If you wanted this program to draw a red pie slice, what could you do?


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