FileDocCategorySizeDatePackage
Rotate.javaAPI DocExample5382Wed Aug 08 15:13:48 BST 2001demos.Transforms

Rotate

public class Rotate extends ControlsSurface
Rotate ellipses with controls for increment and emphasis. Emphasis is defined as which ellipses have a darker color and thicker stroke.

Fields Summary
protected double
increment
protected int
emphasis
Constructors Summary
public Rotate()



      
        setBackground(Color.white);
        setControls(new Component[] { new DemoControls(this) });
    
Methods Summary
public static voidmain(java.lang.String[] s)

        createDemoFrame(new Rotate());
    
public voidrender(int w, int h, java.awt.Graphics2D g2)

        int size = Math.min(w, h);
        float ew = size/4;
        float eh = size-20;
        Ellipse2D ellipse = new Ellipse2D.Float(-ew/2, -eh/2, ew, eh);
        for (double angdeg = 0; angdeg < 360; angdeg+=increment) {
            if (angdeg % emphasis == 0) {
                g2.setColor(Color.gray);
                g2.setStroke(new BasicStroke(2.0f));
            } else {
                g2.setColor(Color.lightGray);
                g2.setStroke(new BasicStroke(0.5f));
            }
            AffineTransform at = AffineTransform.getTranslateInstance(w/2, h/2);
            at.rotate(Math.toRadians(angdeg));
            g2.draw(at.createTransformedShape(ellipse));
        }
        g2.setColor(Color.blue);
        ellipse.setFrame(w/2-10,h/2-10,20,20);
        g2.fill(ellipse);
        g2.setColor(Color.gray);
        g2.setStroke(new BasicStroke(6));
        g2.draw(ellipse);
        g2.setColor(Color.yellow);
        g2.setStroke(new BasicStroke(4));
        g2.draw(ellipse);
        g2.setColor(Color.black);
        g2.drawString("Rotate", 5, 15);