Tue Nov 11, 2008 9:07 pm
import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;
public class RotationWithTransform extends JComponent {
Shape shape;
public RotationWithTransform() {
shape = create();
}
protected Shape create() {
float fl = 100 / 2.00f;
return new Ellipse2D.Float(fl, fl, 2 * fl, fl);
}
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
AffineTransform affineTransform = AffineTransform.
getTranslateInstance(50, 50);
g2d.transform(affineTransform);
g2d.setPaint(Color.red);
g2d.draw(shape);
g2d.transform(AffineTransform.getRotateInstance(-Math.PI / 7));
Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_BEVEL, 0, new float[] { 3, 1 }, 0);
g2d.setStroke(stroke);
g2d.draw(shape);
}
public static void main(String[] a) {
JFrame frame = new JFrame("Rotate using Transform");
frame.getContentPane().add(new RotationWithTransform());
frame.setSize(300, 200);
frame.show();
}
}
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.