4.3 Drawing Shapes and Text

Now we’re ready to create some graphics. Let’s start with drawing lines.

Table 4.5 shows some useful methods of the GraphicsContext class for drawing shapes and displaying text in a window.

As you can see, all these methods have a void return type, so they do not return a value. Method calls to these methods should be stand-alone statements.

The pattern for the method names is simple. The draw methods render the outline of the figure, while the fill methods render solid figures. The clearRect method draws a rectangle in the background color, which effectively erases anything drawn within that rectangle.

Figure 4.4 shows the relationship among the method arguments and the figures drawn.

TABLE 4.5 Drawing Methods ...

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.