Total members 11890 |It is currently Tue Apr 23, 2024 7:58 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 19540 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     -  
 Java course     -  
 need help in java     -  
 What is Java API?!!!     -  
 Using FTP in java     -  
 java or .net     -  
 what is java     -  
 Fonts in java     -  
 Inheritance 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
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