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 8825201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:49:19+00:00 2026-06-14T06:49:19+00:00

I’ve done quite a bit with the acm graphics library in the past and

  • 0

I’ve done quite a bit with the acm graphics library in the past and I’ve just begun working on the breakout problem that Stanford assigns. One of the issues which I’ve had several times in the past with graphics is the coordinates do not accurately reflect where the shapes are actually appearing although I’ve double and triple checked them. In the end, for those assignments I ended up eyeballing it and making modifications until it look kind of right. So obvious I’m missing something here cause a simple graphics program should not be this difficult.

For example, using acm.graphics my code looks like this.

public static final int APPLICATION_WIDTH = 400;
public static final int APPLICATION_HEIGHT = 600;

public void setupBorder(){
    // **Sets Black Background
    GRect b = new GRect(0,0,400,600);  //** Sets Black Background
    fillObj(b,Color.black);
    add(b);

    //**Sets White Square so border is 5 pixels wide on each side
    b = new GRect(5,5,APPLICATION_WIDTH-10,APPLICATION_HEIGHT-10);
    fillObj(b,Color.white);
    add(b);
    }

So my thinking here, is its moved 5 pixels right and 5 pixels down I need to subtract those and then an extra 5 pixels to have a border 5 pixels on each side (basic 2b+x = 1 side, 2a+y= vertical side). You would think this creates a black border 5 pixels on each side with a white square in the middle, but it doesn’t. It creates a border on the left, right, and top side of the window but not the bottom. So with something this simple, what can possibly go wrong? I’ve double, triple, even quad checked the calculations on paper and it should be a white square in the middle with a 5 pixel black border, but it isn’t. I’ve tried changing pixels for percentages, with worse effect. Manually editing the box till it looks close at about -35 for the Yvalue although that’s just a bit too far. Anyone have an idea about what’s going wrong?

appwindow

Breakout with these changes made to run and other methods within class.

public void run() {
    /* You fill this in, along with any subsidiary methods */
    init();
}

public void init(){

    setupBorder();


}

public void setupBorder(){
    //**Black Background
    GRect b = new GRect(0,0,400,600);  //**Black Background
    fillObj(b,Color.black);
    add(b);

    b = new GRect(5,5,APPLICATION_WIDTH-10,APPLICATION_HEIGHT-10);
    fillObj(b,Color.white);
    add(b);
}

public void fillObj(GFillable a, Color argC)
{
    a.setFillColor(argC);
    a.setFilled(true);
}
  • 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-06-14T06:49:20+00:00Added an answer on June 14, 2026 at 6:49 am

    It looks like you’re confusing the size of the application window (excluding the window border but including the menu, and which is 400*600 in your case) with the size of your drawable area (excluding the menu), which means you’re painting outside the drawable area (which is below the menu.

    Your window has:

    • a border supplied by the OS. It is 400×600 on the inside.
    • a menu bar.
    • a drawable area (canvas) below the the menu bar. It is shorter than 400×600 by the menu bar width.

    You either

    • need to read the canvas size and use it instead of the window size: getCanvas().getHeight()
    • need to set the canvas size instead of the window size and let the window size itself as needed. As GraphicsProgram is an Applet, this doesn’t seem possible.
    • need to find out the menu height and increase the window height by that amount (last resort).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

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.