Calculate Rotation Transform with Math.PI : Tranformation « 2D Graphics « Java Tutorial

Calculate Rotation Transform with Math.PI
import java.awt.Canvas;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.geom.AffineTransform;
import java.awt.geom.Line2D;

import javax.swing.JFrame;

public class Draw2DRotate extends JFrame {
  public static void main(String args[]) {
    Draw2DRotate app = new Draw2DRotate();

  public Draw2DRotate() {
    add("Center", new MyCanvas());

    setSize(400, 400);


class MyCanvas extends Canvas {
  public void paint(Graphics graphics) {
    Graphics2D g = (Graphics2D) graphics;
    AffineTransform transform = AffineTransform.getRotateInstance(Math.PI / 16.0d);
    Line2D.Double shape = new Line2D.Double(0.0, 0.0, 300.0, 300.0);
    g.setFont(new Font("Helvetica", Font.BOLD, 24));
    String text = ("Java2s");
    g.drawString(text, 300, 50);
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Image image = toolkit.getImage("image1.gif");
    g.drawImage(image, 100, 150, this);

16.3.1.Transform LabTransform Lab
16.3.2.Coordinate Translation.
16.3.3.Rotation and coordinate translation
16.3.4.Rotate a line of character (String)
16.3.5.Scaling an object
16.3.6.Tranformation with AffineTransform.getScaleInstanceTranformation with AffineTransform.getScaleInstance
16.3.7.Tranformation with AffineTransform.getTranslateInstanceTranformation with AffineTransform.getTranslateInstance
16.3.8.Tranformation with AffineTransform.getShearInstanceTranformation with AffineTransform.getShearInstance
16.3.9.Calculate Rotation Transform with Math.PICalculate Rotation Transform with Math.PI
16.3.10.Rotating image using Java 2D AffineTransform class
16.3.11.Translate and rotate all objects
16.3.12.Move and scale graphical objects with a mouse on the panel
16.3.13.Rotates a shape about the specified coordinates.