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

  • SEARCH
  • Home
  • 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 6120169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:38:16+00:00 2026-05-23T15:38:16+00:00

I cam across this recently : here public int print(Graphics g, PageFormat pf, int

  • 0

I cam across this recently : here

 public int print(Graphics g, PageFormat pf, int page) throws
                                                    PrinterException {

    if (page > 0) { /* We have only one page, and 'page' is zero-based */
        return NO_SUCH_PAGE;
    }

    /* User (0,0) is typically outside the imageable area, so we must
     * translate by the X and Y values in the PageFormat to avoid clipping
     */
    Graphics2D g2d = (Graphics2D)g;
    g2d.translate(pf.getImageableX(), pf.getImageableY()); // line 2

    g.drawString("Hello world!", 100, 100);

    /* tell the caller that this page is part of the printed document */
    return PAGE_EXISTS;
}

I don’t understand the line 2 (commented) in this snippet.(g2d.translate(pf.getImageableX(), pf.getImageableY());) g2d is a reference of Graphics2dand translate is a method found in Graphic class. Then how does it work ?

  • 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-23T15:38:17+00:00Added an answer on May 23, 2026 at 3:38 pm

    Edit: The translate method is found in both the Graphics2D class and in the Graphics class since Graphics2D is a child class of Graphics. Being a child of Graphics, it implements all of its methods (including translate), which is why it works.

    The translate method in your example is used to move the g2d’s origin point to pf’s origin point.

    Basically, what it does is tell the program to translate (move) every point from g2d to pf’s corresponding point.

    Let’s say g2d starts at (0,0) and pf starts at (100,100), after the translation, g2d’s (0,100) point would now be at (100,200), which is pf’s (0,100) point since it doesn’t start at the same place.

    I’m having a hard time making it clear and easy to understand, but if you don’t understand what I mean, I’ll try explaining it better or just delete the answer altogether and let someone else explain it.

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

Sidebar

Related Questions

I was working on my website when I cam across this problem, I have
I cam across a Java related question recently that was (to paraphrase): What reasons
Recently i cam across a statements : import static java.lang.System.out; import static java.lang.System.exit; I
Say you have this code pthread_mutex_lock(&cam->video_lock); while(cam->status == WAIT_DISPLAY) // <-- Why is this
I have a web cam that takes a picture every N seconds. This gives
I have a bunch of short videos from my digital cam. i know how
I have written code in Java to access web cam,and to save image... I
I have XML like, <items> <item> <products> <product>laptop</product> <product>charger</product> <product>Cam</product> </products> </item> <item> <products>
I have come across a couple of different ways to write images to isolated
I cam across the following function in javascript: for (var number = 0; number

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.