FileDocCategorySizeDatePackage
LineStyles.javaAPI DocExample3643Sat Jan 24 10:44:36 GMT 2004je3.graphics

LineStyles

public class LineStyles extends Object implements GraphicsExample
A demonstration of Java2D line styles

Fields Summary
int[]
xpoints
int[]
ypoints
Stroke[]
linestyles
Stroke
thindashed
Font
font
String[]
capNames
String[]
joinNames
Constructors Summary
Methods Summary
public voiddraw(java.awt.Graphics2D g, java.awt.Component c)
This method draws the example figure


           
          
	// Use anti-aliasing to avoid "jaggies" in the lines
	g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 
			   RenderingHints.VALUE_ANTIALIAS_ON);

	// Define the shape to draw
	GeneralPath shape = new GeneralPath();
	shape.moveTo(xpoints[0], ypoints[0]);   // start at point 0
	shape.lineTo(xpoints[1], ypoints[1]);   // draw a line to point 1
	shape.lineTo(xpoints[2], ypoints[2]);   // and then on to point 2

	// Move the origin to the right and down, creating a margin
	g.translate(20,40);

	// Now loop, drawing our shape with the three different line styles
	for(int i = 0; i < linestyles.length; i++) {
	    g.setColor(Color.gray);       // Draw a gray line
	    g.setStroke(linestyles[i]);   // Select the line style to use
	    g.draw(shape);                // Draw the shape

	    g.setColor(Color.black);      // Now use black
	    g.setStroke(thindashed);      // And the thin dashed line
	    g.draw(shape);                // And draw the shape again.

	    // Highlight the location of the vertexes of the shape
	    // This accentuates the cap and join styles we're demonstrating
	    for(int j = 0; j < xpoints.length; j++) 
		g.fillRect(xpoints[j]-2, ypoints[j]-2, 5, 5);

	    g.drawString(capNames[i], 5, 105);   // Label the cap style
	    g.drawString(joinNames[i], 5, 120);  // Label the join style

	    g.translate(150, 0); // Move over to the right before looping again
	}
    
public intgetHeight()

 return 180; 
public java.lang.StringgetName()

 return "LineStyles"; 
public intgetWidth()

 return 450;