Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions? | Software Development
 

Show Scaling property of class AffineTransform

To show the scaling, we have used Ellipse2D class to draw the oval. The method getTranslateInstance() returns the translation transformation.

Show Scaling property of class AffineTransform

                         

This section shows you the scaling property.

To show the scaling, we have used Ellipse2D class to draw the oval. The method getTranslateInstance() returns the translation transformation. The method draw(shape) draws the specified shape in the original location. The method scale(3 ,3) performs a scaling transformation.

Following code transform the Graphics2D:

AffineTransform affineTransform2 = AffineTransform.getTranslateInstance(0, 0);
affineTransform2.scale(3, 3);
g2d.transform(affineTransform2);

To give the stylistic representation of the outline for the specified shape, interface Stroke is used. The set of rendering attributes for the outlines of graphics primitives has been defined by the class BasicStroke. The BasicStroke.CAP_BUTT gives the dash segments. The BasicStroke.JOIN_BEVEL joins the path segments by connecting the outer corners of their wide outlines with a straight segment.

 Following code draws the specified shape in dashed format:

Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT,
BasicStroke.JOIN_BEVEL, 0, new float[] { 3, 1 }, 0);
g2d.setStroke(stroke);
g2d.draw(shape);

The method setStroke() sets the stroke settings for the Graphics2D context.

Here is the code of ScaleWithTransform.java

import java.awt.*;
import javax.swing.*;
import java.awt.geom.*;

public class ScaleWithTransform extends JComponent {
  Shape shape;
  public ScaleWithTransform() {
  shape = create();
  }
  private Shape create() {
  return new Ellipse2D.Double(1005010050);
  }
  public void paint(Graphics g) {
    Graphics2D g2d = (Graphics2D) g;
    AffineTransform affineTransform1 = AffineTransform.
        getTranslateInstance(
00);
    g2d.transform(affineTransform1);
    g2d.setPaint(Color.red);
    g2d.draw(shape);

    AffineTransform affineTransform2 = AffineTransform.
        getTranslateInstance(
00);
      affineTransform2.scale(33);
      g2d.transform(affineTransform2);
      g2d.transform(AffineTransform.getTranslateInstance(00));
      
    Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT,
        BasicStroke.JOIN_BEVEL, 0new float[] { 3}, 0);
    g2d.setStroke(stroke);
    g2d.draw(shape);
  }
    public static void main(String[] args) {
    JFrame frame = new JFrame("Scaling using Transform");
    frame.getContentPane().add(new ScaleWithTransform());
    frame.setSize(620350);
    frame.show();
  }
}

Output will be displayed as:

Download Source Code

                         

» View all related tutorials
Related Tags: c string com class orm ant form object io sed format screen font display vi metrics id render oo define

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
 
Tell A Friend
Your Friend Name

 

 
Recently Viewed
Software Solutions
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.