Switch to full style
General Java code examples
Post a reply

Rotation in java

Tue Nov 11, 2008 9:07 pm

Rotation in java graphics
java code
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();
}
}



Attachments
rotate.gif
rotate in java
rotate.gif (4.83 KiB) Viewed 19738 times

Post a reply
  Related Posts  to : Rotation in java
 Line Rotation 2D     -  
 2d game in java-Monster-Java 2D Game Graphics and Animation     -  
 Java course     -  
 need help in java     -  
 What is Java API?!!!     -  
 Using FTP in java     -  
 java or .net     -  
 what is java     -  
 packages in java     -  
 how to start java .     -  

Topic Tags

Java Graphics