Transform Scale : Transform « 2D Graphics GUI « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. Email
14. Event
15. File Input Output
16. Game
17. Generics
18. Hibernate
19. I18N
20. J2EE
21. J2ME
22. JDK 6
23. JSP
24. JSTL
25. Language Basics
26. Network Protocol
27. PDF RTF
28. Reflection
29. Regular Expressions
30. Scripting
31. Security
32. Servlets
33. Spring
34. Swing Components
35. Swing JFC
36. SWT JFace Eclipse
37. Threads
38. Tiny Application
39. Velocity
40. Web Services SOA
41. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » 2D Graphics GUI » TransformScreenshots 
Transform Scale
Transform Scale


import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.Stroke;
import java.awt.geom.AffineTransform;
import java.awt.geom.GeneralPath;
import java.awt.geom.Rectangle2D;

import javax.swing.JComponent;
import javax.swing.JFrame;

public class TransformScale extends JComponent {
  Shape axes, shape;

  int length = 54, arrowLength = 4, tickSize = 4;

  public TransformScale() {
    axes = createAxes();
    shape = createShape();
  }

  protected Shape createAxes() {
    GeneralPath path = new GeneralPath();

    // Axes.
    path.moveTo(-length, 0);
    path.lineTo(length, 0);
    path.moveTo(0, -length);
    path.lineTo(0, length);
    // Arrows.
    path.moveTo(length - arrowLength, -arrowLength);
    path.lineTo(length, 0);
    path.lineTo(length - arrowLength, arrowLength);
    path.moveTo(-arrowLength, length - arrowLength);
    path.lineTo(0, length);
    path.lineTo(arrowLength, length - arrowLength);
    // Half-centimeter tick marks
    float cm = 72 2.54f;
    float lengthCentimeter = length / cm;
    for (float i = 0.5f; i < lengthCentimeter; i += 1.0f) {
      float tick = i * cm;
      path.moveTo(tick, -tickSize / 2);
      path.lineTo(tick, tickSize / 2);
      path.moveTo(-tick, -tickSize / 2);
      path.lineTo(-tick, tickSize / 2);
      path.moveTo(-tickSize / 2, tick);
      path.lineTo(tickSize / 2, tick);
      path.moveTo(-tickSize / 2, -tick);
      path.lineTo(tickSize / 2, -tick);
    }
    // Full-centimeter tick marks
    for (float i = 1.0f; i < lengthCentimeter; i += 1.0f) {
      float tick = i * cm;
      path.moveTo(tick, -tickSize);
      path.lineTo(tick, tickSize);
      path.moveTo(-tick, -tickSize);
      path.lineTo(-tick, tickSize);
      path.moveTo(-tickSize, tick);
      path.lineTo(tickSize, tick);
      path.moveTo(-tickSize, -tick);
      path.lineTo(tickSize, -tick);
    }
    return path;
  }

  protected Shape createShape() {
    float cm = 72 2.54f;
    return new Rectangle2D.Float(cm, cm, * cm, cm);
  }

  public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2Dg;

    // Use antialiasing.
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
        RenderingHints.VALUE_ANTIALIAS_ON);

    // Move the origin to 75, 75.
    AffineTransform at = AffineTransform.getTranslateInstance(7575);
    g2.transform(at);

    // Draw the shapes in their original locations.
    g2.setPaint(Color.black);
    g2.draw(axes);
    g2.draw(shape);

    // Transform the Graphics2D.
      g2.transform(AffineTransform.getScaleInstance(33));

    // Draw the "new" shapes in dashed.
      g2.transform(AffineTransform.getTranslateInstance(7575));
      
    Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT,
        BasicStroke.JOIN_BEVEL, 0new float[] { 3}0);
    g2.setStroke(stroke);
    g2.draw(axes);
    g2.draw(shape);
  }

  public static void main(String[] a) {
    JFrame f = new JFrame();
    f.getContentPane().add(new TransformScale());
    f.setSize(650550);
    f.show();
  }
}

           
       
Related examples in the same category
1. Coordinate DemoCoordinate Demo
2. Transform DemoTransform Demo
3. Transform ShearTransform Shear
4. Transform Rotation Translation Transform Rotation Translation
5. Transforme Rotation demoTransforme Rotation demo
6. Transform Translation and RotationTransform Translation and Rotation
7. Transform Translated RotationTransform Translated Rotation
8. Transform TranslationTransform Translation
9. Line transformation, rotation, shear,scale Line transformation, rotation, shear,scale
10. AffineTransform demoAffineTransform demo
11. Transform TestTransform Test
ww_w.___j__a__v__a_2s__._c__o___m__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.