... endpoints, and lines 35–36 generate a random color. Line 39 creates a new MyLine object with the randomly generated values and stores it in the array. Finally, lines 43–47 clear the Canvas then iterate through the MyLine objects in array lines using an enhanced for statement. Each iteration calls the current MyLine’s draw method and passes it the Canvas’s GraphicsContext. The MyLine object actually draws itself.

 1   // Fig. 8.18: DrawRandomLinesController.java
 2   // Drawing random lines using MyLine objects.
 3   import java.security.SecureRandom;
 4   import javafx.event.ActionEvent;
 5   import javafx.fxml.FXML;
 6   import javafx.scene.canvas.Canvas;
 7   import javafx.scene.canvas.GraphicsContext;
 8   import javafx.scene.paint.Color;
 9   import javafx.scene.shape.ArcType; ...

Get Java How to Program, Early Objects, 11th 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.