7.17 (Optional) GUI and Graphics Case Study: Drawing Arcs

In this section, we build a Draw Rainbow app that uses arrays and iteration statements to draw a rainbow with GraphicsContext method fillArc. Drawing arcs in JavaFX is similar to drawing ovals—an arc is simply a section of an oval.

Creating the Draw Rainbow App’s GUI

The app’s GUI is defined in DrawRainbow.fxml. We reused the DrawLines.fxml GUI shown in Fig. 4.17, but made the following changes to DrawRainbow.fxml:

  • We specified DrawRainbowController as the app’s Controller class in the Scene Builder Document window’s Controller section.

  • We set the Button’s Text property to Draw Rainbow (in the Inspector’s Properties section) and set the Button’s On Action event handler to drawRainbowButtonPressed ...

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.