Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6533545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:08:24+00:00 2026-05-25T10:08:24+00:00

I am working on a task which includes data such as length of a

  • 0

I am working on a task which includes data such as “length” of a road in “millimetre”. And as per the specification my JFrame should be 4meter * 3meter ( How to convert this into device coordinate…?).

Now, I know at least that this data is real world data and not device’s pixel data. However after finding out few sources you can actually transform these data into pixel by Graphics2D class.

Resource I found these information is in,

Core Java 2, Volume II – Advanced Feature, Author – Cay S. Horstmann & Gary Cornell

However, I googled for actual examples with no luck.

Does anyone know any source where I can read more about this. And if you have any examples where someone has actually did something like this, That would be more informative.

Research so far : So far I know that we need to give a assumptions to Graphics2D class of number of pixels in meters. In Graphics2D there is method which helps you to set this assumption. Method is ,

g2D.scale(pixelsPerMeter, pixelsPerMeter);
//And than I can draw a line with meter or millimetre coordinates
g2D.draw(new Line2D.Double(coordinates in meter));

I tried above code but really hard to draw line where I actually want to.

Any help of understanding will be very helpful.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T10:08:25+00:00Added an answer on May 25, 2026 at 10:08 am

    I find it easier to create an
    java.awt.geom.AffineTransform
    object and transform the coordinates from meters to pixels myself.
    In your case, use AffineTransform.getScaleInstance(sx, sy).

    Then I call Graphics2D functions to draw my lines and polygons
    using pixel coordinates.

    This makes debugging easier: you can see the coordinate values before
    and after the transformation.

    The Advanced Topics section in the Java Tutorial describes how
    to do transformations with Graphics2D, with examples:
    http://download.oracle.com/javase/tutorial/2d/index.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a Rails 3 task demo project in which each instance of
I'm trying to write a Gradle task which copies generated war files to my
I have a task which i need to cancel if the wait time is
I'm working this programming task for college where we have to write a c++
I am currently automating the build of our .NET solution (which contains many projects,
Hi i have a small application with spring and i've been adding security which
I'm very new to MSBuild and am having trouble figuring out how to construct
For the first time, I am writing a web service that will call upon
This is kind of hard to explain. Basically it's kind of like a simple
During capistrano deployment of a Rails3 app, I want my server to install gems,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.