June 2017
Beginner
1296 pages
69h 23m
English
... 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; ...Read now
Unlock full access