Example usage for java.awt Graphics2D setTransform

List of usage examples for java.awt Graphics2D setTransform

Introduction

In this page you can find the example usage for java.awt Graphics2D setTransform.

Prototype

public abstract void setTransform(AffineTransform Tx);

Source Link

Document

Overwrites the Transform in the Graphics2D context.

Usage

From source file:Main.java

public void paint(Graphics g) {
    Shape shape = new Rectangle2D.Float(100, 50, 80, 80);

    Graphics2D g2 = (Graphics2D) g;

    AffineTransform at = new AffineTransform();
    at.setToTranslation(Math.PI / 6, Math.PI / 6);

    g2.setTransform(at);
    g2.draw(shape);/*from   ww  w  .ja  v a  2s.  c  o m*/

}

From source file:Main.java

public void paint(Graphics g) {
    Shape shape = new Rectangle2D.Float(100, 50, 80, 80);

    Graphics2D g2 = (Graphics2D) g;

    AffineTransform at = new AffineTransform();
    at.transform(new Point(1, 2), new Point(2, 3));

    g2.setTransform(at);
    g2.draw(shape);/*w w w.ja v  a  2  s .c  om*/

}

From source file:BasicDraw.java

public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    AffineTransform tx = new AffineTransform();

    double radians = -Math.PI / 4;
    tx.rotate(radians);/*  w w  w .j  av  a  2  s.  c om*/

    g2d.setTransform(tx);
    g2d.drawImage(new ImageIcon("a.png").getImage(), tx, this);
}

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    AffineTransform at = new AffineTransform();
    at.setToRotation(-Math.PI / 2.0, getWidth() / 2.0, getHeight() / 2.0);
    g2d.setTransform(at);
    g2d.drawString("Vertical text", 10, 10);
}

From source file:Main.java

public void paint(Graphics g) {
    Shape shape = new Rectangle2D.Float(100, 50, 80, 80);

    Graphics2D g2 = (Graphics2D) g;

    AffineTransform at = new AffineTransform();
    at.setTransform(AffineTransform.getRotateInstance(0.5));

    g2.setTransform(at);
    g2.draw(shape);/*from  w  w w  . ja  v  a  2 s .com*/

}

From source file:BasicDraw.java

public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    AffineTransform tx = new AffineTransform();

    double x = 50;
    double y = 50;
    tx.translate(x, y);/*w ww  . j a  v  a  2  s.c o m*/

    g2d.setTransform(tx);
    g2d.drawImage(new ImageIcon("a.png").getImage(), tx, this);
}

From source file:MainClass.java

public void paint(Graphics g) {
    Shape shape = new Rectangle2D.Float(100, 50, 80, 80);

    Graphics2D g2 = (Graphics2D) g;

    AffineTransform at = new AffineTransform();
    at.setToRotation(Math.PI / 6);
    at.translate(100, 0);//from w w  w . jav a  2  s  .  c  om

    g2.setTransform(at);
    g2.draw(shape);

}

From source file:MainClass.java

public void paint(Graphics g) {
    Shape shape = new Rectangle2D.Float(100, 50, 80, 80);

    Graphics2D g2 = (Graphics2D) g;

    float cm = 72 / 2.54f;
    AffineTransform at = AffineTransform.getRotateInstance(-Math.PI / 6, 3 * cm, 2 * cm);

    g2.setTransform(at);
    g2.draw(shape);//w w  w .ja  v a 2s  .c om

}

From source file:BasicDraw.java

public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;

    g2d.drawString("aString", 100, 100);
    AffineTransform at = new AffineTransform();
    at.setToRotation(Math.PI / 4.0);
    g2d.setTransform(at);
    g2d.drawString("aString", 100, 100);

}

From source file:Main.java

public void paint(Graphics g) {
    Shape shape = new Rectangle2D.Float(100, 50, 80, 80);

    Graphics2D g2 = (Graphics2D) g;

    AffineTransform at = new AffineTransform();
    at.setToRotation(Math.PI / 6, Math.PI / 6);
    at.translate(100, 0);/*  w  w  w.  j  a  v a 2 s  . c o m*/

    g2.setTransform(at);
    g2.draw(shape);

}