The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.awt  [78 examples] > Shapes  [5 examples]

e589. Stroking or Filling a Shape

A stroked shape is an outline of the shape. A filled shape is drawn with filled with a color. See also e575 The Quintessential Drawing Program.
    public void paint(Graphics g) {
        Graphics2D g2d = (Graphics2D)g;
    
        // Set pen color for stroked shape
        g2d.setColor(Color.red);
    
        // Stroke the shape
        g2d.draw(shape);
    
    
        // Set fill color for filled shape
        g2d.setColor(Color.blue);
    
        // Fill the shape
        g2d.fill(shape);
    }

 Related Examples
e586. Drawing Simple Shapes
e587. Filling Basic Shapes
e588. Creating a Shape from a Stroked Shape
e590. Drawing a Pie Chart

See also: Colors    Components    Containers    Cursors    Drawing    Events    Focus    Frames    GridBagLayout    Images    Simulating Events    Text    The Screen   


© 2002 Addison-Wesley.