GUI and Graphics Case Study Exercises

6.1 Using method fillOval, draw a bull’s-eye that alternates between two random colors, as in Fig. 6.13. Use the constructor Color(int r, int g, int b) with random arguments to generate random colors.

Image

Fig. 6.13 | A bulls-eye with two alternating, random colors.

6.2 Create a program that draws 10 random filled shapes in random colors, positions and sizes (Fig. 6.14). Method paintComponent should contain a loop that iterates 10 times. In each iteration, the loop should determine whether to draw a filled rectangle or an oval, create a random color and choose coordinates and dimensions at random. The coordinates ...

Get Java™ How To Program (Early Objects), Tenth 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.