FileDocCategorySizeDatePackage
Shapes.javaAPI DocExample3611Sat Jan 24 10:44:36 GMT 2004je3.graphics

Shapes

public class Shapes extends Object implements GraphicsExample
A demonstration of Java2D shapes

Fields Summary
static final int
WIDTH
static final int
HEIGHT
Shape[]
shapes
String[]
labels
Constructors Summary
Methods Summary
public voiddraw(java.awt.Graphics2D g, java.awt.Component c)
Draw the example


        
          
	// Set basic drawing attributes
	g.setFont(new Font("SansSerif", Font.PLAIN, 10));      // select font
	g.setStroke(new BasicStroke(2.0f));                    // 2 pixel lines
	g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,    // antialiasing
			   RenderingHints.VALUE_ANTIALIAS_ON);
	g.translate(10, 10);                                   // margins

	// Loop through each shape
	for(int i = 0; i < shapes.length; i++) {
	    g.setColor(Color.yellow);            // Set a color
	    g.fill(shapes[i]);                   // Fill the shape with it
	    g.setColor(Color.black);             // Switch to black
	    g.draw(shapes[i]);                   // Outline the shape with it
	    g.drawString(labels[i], 0, 110);     // Label the shape
	    g.translate(120, 0);                 // Move over for next shape
	    if (i % 6  == 5) g.translate(-6*120, 120);  // Move down after 6
	}
    
public intgetHeight()

 return HEIGHT; 
public java.lang.StringgetName()

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

 return WIDTH;