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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.