Creating Your Own Shapes with General Paths

Next we present a general path—a shape constructed from straight lines and complex curves. A general path is represented with an object of class GeneralPath (package java.awt.geom). The application of Figs. 13.31 and 13.32 demonstrates drawing a general path in the shape of a five-pointed star.

 1   // Fig. 13.31: Shapes2JPanel.java 2   // Demonstrating a general path. 3   import java.awt.Color; 4   import java.awt.Graphics; 5   import java.awt.Graphics2D; 6   import java.awt.geom.GeneralPath; 7   import java.security.SecureRandom; 8   import javax.swing.JPanel; 9 10   public class Shapes2JPanel extends JPanel11   {12      // draw general paths13      @Override14       ...

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.