Total members 11667 |It is currently Thu Oct 19, 2017 12:45 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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:
File comment: rotate in java
rotate.gif
rotate.gif [ 4.83 KiB | Viewed 16698 times ]
Author:
Mastermind
User avatar Posts: 2707
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : Rotation in java
 Line Rotation 2D     -  
 2d game in java-Monster-Java 2D Game Graphics and Animation     -  
 need help in java     -  
 What is Java API?!!!     -  
 Using FTP in java     -  
 java or .net     -  
 what is java     -  
 Java course     -  
 Help for jprogressbar of java     -  
 How to use Generics in java     -  



Topic Tags

Java Graphics







Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team