... strokeRectanglesButtonPressed(ActionEvent event) { 14         draw("rectangles");
15      }
16
17      // when user presses Draw Ovals button, call draw for ovals
18      @FXML
19      void strokeOvalsButtonPressed(ActionEvent event) {
20         draw("ovals");
21      }
22
23      // draws rectangles or ovals based on which Button the user pressed
24      public void draw(String choice) {
25         // get the GraphicsContext, which is used to draw on the Canvas
26         GraphicsContext gc = canvas.getGraphicsContext2D();
27
28         // clear the canvas for next set of shapes
29         gc.clearRect(0, 0, canvas.getWidth(), canvas.getHeight());
30
31         int step = 10;
32
33         // draw 10 overlapping shapes
34         for (int i = 0; i < 10; i++) {
35            // pick the shape based on the user's choice
36            switch (choice) {
37               case "rectangles": // draw rectangles ...

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.