Total members 11894 |It is currently Fri Nov 22, 2024 8:03 pm 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 19739 times ]

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada
Author:
Mastermind
User avatar Posts: 2715
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     -  
 How to use Generics in java     -  
 java program     -  



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
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