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

Answer:

You could use a sequence of 9 individual Lines.

Or, you could use a single Polyline.


Polyline

Polyline

A Polyline shape is a sequence of connected line segments. The end of one line segment is the beginning of the next. This is just like a Polygon, except the first and last points are not connected.

The Polyline constructor looks just like that for Polygon:

public Polyline(double... points)

The parameters are the endpoints of the polyline as a comma-separated list, each vertex as two X Y values, with the endpoints in sequence. The number of lines of the polyline is the number of endpoints minus one.

Here is the code that draws the above polyline:


import javafx.application.*;
import javafx.stage.*;
import javafx.scene.Scene;  
import javafx.scene.shape.*;
import javafx.scene.paint.*;
import javafx.scene.layout.*; 
import java.util.Scanner;

public class PolylineDemo extends Application
{
 
  public void start( Stage primaryStage )
  {
    double sceneWidth = 400.0, sceneHeight = 200.0;
     
    // array of vertices x,y, x,y, x,y    
    double[] vertices =   
    { 25,75, 75,125, 125,50, 100,15, 200,60, 225,150, 300,25, 235,55, 340,90, 375,50 }; 
    
    Polyline line = new Polyline( vertices ); 
    line.setStroke( Color.BLACK ); 
    line.setStrokeWidth( 2.4 ); 
    
    Pane pane = new Pane( line  );
    Scene scene = new Scene( pane, sceneWidth, sceneHeight, Color.ALICEBLUE);
    
    primaryStage.setTitle("Polyline Demo");
    primaryStage.setScene( scene );
    primaryStage.show();
  }
}

QUESTION 12:

Z

Complete this program fragment so that it draws a "Z" connecting the midpoints of the four quadrants.

double sceneWidth = 200.0, sceneHeight = 200.0;
double w = sceneWidth, h = sceneHeight;
 
// array of vertices x,y, x,y, x,y, x,y
double[] vertices =  
{ , , , , , , ,   }; 

Polyline line = new Polyline( vertices );

Use either literals or expressions involving w or z.


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