Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-21-2008, 09:53 PM
Moderator
 
Join Date: Nov 2007
Posts: 1,657
Java Tip will become famous soon enoughJava Tip will become famous soon enough
Transform Scale
Code:
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, 2 * cm, cm); } public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; // Use antialiasing. g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Move the origin to 75, 75. AffineTransform at = AffineTransform.getTranslateInstance(75, 75); 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(3, 3)); // Draw the "new" shapes in dashed. g2.transform(AffineTransform.getTranslateInstance(75, 75)); Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 3, 1 }, 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(650, 550); f.show(); } }
__________________
Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums! (closes on July 27, 2008)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Transform Shear Java Tip java.awt 0 06-21-2008 09:52 PM
Transform Demo Java Tip java.awt 0 06-21-2008 09:52 PM
Scale 2 or more pictures using a JSlider Panchitopro AWT / Swing 4 05-20-2008 05:44 PM
Scale 2 or more pictures using a JSlider Panchitopro New To Java 0 05-05-2008 06:22 PM
Small scale Java Editor Greenfrog99 AWT / Swing 0 01-27-2008 09:46 PM


All times are GMT +3. The time now is 11:39 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org