4.4 Drawing Custom Shapes

To draw custom shapes we create a path, which consists of a series of coordinates between which the JavaFX platform should draw lines. Our resulting shape can be displayed either outlined or filled. Only one path can be defined at a time. Table 4.7 shows the methods we use to create and display a path.

TABLE 4.7 Path Drawing Methods of the GraphicsContext Class

Return value Method name and argument list
void

beginPath( )

sets the drawing path to empty

void

moveTo( double x, double y )

moves to the (x, y) location without adding a line to the path

void

lineTo( double x, double y )

adds a line to the current path from the previous location to (x, y)

void

closePath( )

closes the path by adding a line ...

Get Java Illuminated, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.