FileDocCategorySizeDatePackage
Stroking.javaAPI DocExample3060Sat Jan 24 10:44:36 GMT 2004je3.graphics

# Stroking

public class Stroking extends Object implements GraphicsExample
 A demonstration of how Stroke objects work

Fields Summary
static final int
WIDTH
static final int
HEIGHT
Constructors Summary
Methods Summary

``````	Polygon p = new Polygon();
double angle = 2 * Math.PI / numsides;   // Angle between vertices
for(int i = 0; i < numsides; i++)  // Compute location of each vertex
return p;
``````
public voiddraw(java.awt.Graphics2D g, java.awt.Component c)
Draw the example

``````	// Create the shape we'll work with.  See convenience method below.
Shape pentagon = createRegularPolygon(5, 75);

// Set up basic drawing attributes
g.setColor(Color.black);                          // Draw in black
g.setStroke(new BasicStroke(1.0f));               // Use thin lines
g.setFont(new Font("SansSerif", Font.PLAIN, 12)); // Basic small font

g.translate(100, 100);                        // Move to position
g.draw(pentagon);                             // Outline the shape
g.drawString("The shape", -30, 90);           // Draw the caption

g.translate(175, 0);                          // Move over
g.fill(pentagon);                             // Fill the shape
g.drawString("The filled shape", -50, 90);    // Another caption

// Now use a Stroke object to create a "stroked shape" for our shape
BasicStroke wideline = new BasicStroke(10.0f);
Shape outline = wideline.createStrokedShape(pentagon);

g.translate(175, 0);                          // Move over
g.draw(outline);                              // Draw the stroked shape
g.drawString("A Stroke creates",-50,90);      // Draw the caption
g.drawString("a new shape", -35, 105);

g.translate(175,0);                           // Move over
g.fill(outline);                              // Fill the stroked shape
g.drawString("Filling the new shape",-65,90); // Draw the caption
g.drawString("outlines the old one",-65,105);
``````
public intgetHeight()

`` return HEIGHT; ``
public java.lang.StringgetName()

``````  // Size of our example
return "Stroking";``````
public intgetWidth()

`` return WIDTH; ``