Tue Nov 11, 2008 9:15 pm
import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;
public class ShearWithTransform extends JComponent {
Shape shape;
public ShearWithTransform() {
shape = create();
}
private Shape create() {
return new Ellipse2D.Double(100, 50, 100, 50);
}
public void paint(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
AffineTransform affineTransform1 = AffineTransform.
getTranslateInstance(0, 0);
g2d.transform(affineTransform1);
g2d.setPaint(Color.red);
g2d.draw(shape);
AffineTransform affineTransform2 = AffineTransform.
getTranslateInstance(0, 0);
affineTransform2.shear(-.8, 0);
g2d.transform(affineTransform2);
g2d.transform(AffineTransform.getTranslateInstance(100, 100));
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("Shear the oval");
frame.getContentPane().add(new ShearWithTransform());
frame.setSize(300, 250);
frame.show();
}
}
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
Powered by phpBB © phpBB Group.