(Optional) GUI and Graphics Case Study Exercise: Adding Java 2D

13.31 Java 2D introduces many new capabilities for creating unique and impressive graphics. We’ll add a small subset of these features to the drawing application you created in Exercise 12.17. In this version, you’ll enable the user to specify gradients for filling shapes and to change stroke characteristics for drawing lines and outlines of shapes. The user will be able to choose which colors compose the gradient and set the width and dash length of the stroke.

First, you must update the MyShape hierarchy to support Java 2D functionality. Make the following changes in class MyShape:

a) Change abstract method draw’s parameter type from Graphics to Graphics2D.

b) Change all variables ...

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.