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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:22:33+00:00 2026-05-25T15:22:33+00:00

I am writing a bouncing ball class (I’m just starting to use Java) and

  • 0

I am writing a bouncing ball class (I’m just starting to use Java) and it works but it looks like every time the ball hits an edge the containing box gets bigger

Code for the bounce trigger

    int i = 0;
    int j = 0;
    int k = 0;
    double x = 3;
    double y = 3;
    while(i < 200){
        if(j == 0){
            x += 2; 
        } else {
            x -= 2; 
        }
        if(k == 0){
            y += 4;
        } else {
            y -= 4;
        }
        if(thisEye.getX() > 400){
            j = 1;
        } 
        if(thisEye.getX() < 0) {
            j = 0;
        }
        if(thisEye.getY() > 200){
            k = 1;
        } 
        if(thisEye.getY() < 0) {
            k = 0;
        }
        Color someShade = rGen.nextColor();    // var for the color of the eyes
        Color someOtherShade = rGen.nextColor();// var for the color of the pupules
        moveThis(thisEye,x,y,someShade);     // Go over all the shapes with the same X,Y offset - var x,y
        moveThis(thisPupul,x,y,someOtherShade);
        moveThis(thisEye2,x,y,someShade);
        moveThis(thisPupul2,x,y,someOtherShade);
        moveThis(face,x,y,rGen.nextColor());
        moveThis(nose,x,y,rGen.nextColor());
        pause(150.0);   // wait for next cycle to slow down the images
        //i++;  this was to see if it just got farther off with each loop, it dose.
    }
}

private void moveThis(GOval subject, double x, double y, Color newShade){
    subject.setFillColor(newShade);
    subject.move(x, y);
}

the ‘face’ will bounce off the right spot once then each time it bounces it gets farther and farther off the screen tell is so far of the it only is on screen for a short time then off the other side tell it comes back on screen for a bit.

I marked it as home work but I’m a html/php coder in the day and am just using the iTunesU Stanford videos at night.
but I’m trying to learn so pointers would be great.

  • 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-25T15:22:34+00:00Added an answer on May 25, 2026 at 3:22 pm

    The problem could be (though very unlikely) with your theEye.getX() and theEye.getY() method. What if you change your boundary condition check from

    if(thisEye.getX() > 400){
        j = 1;
    } 
    if(thisEye.getX() < 0) {
        j = 0;
    }
    if(thisEye.getY() > 200){
        k = 1;
    } 
    if(thisEye.getY() < 0) {
        k = 0;
    }
    

    TO

    if(x > 400){
        j = 1;
    } 
    if(x < 0) {
        j = 0;
    }
    if(y > 200){
        k = 1;
    } 
    if(y < 0) {
        k = 0;
    }
    

    Otherwise, please post the complete source code so we can see where else could the problem be.

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

Sidebar

Related Questions

I am writing a bouncing ball game in Java for Android phones. Everything seems
writing somewhat of a css hack, styling for :hover {} works interestingly, but browsers
Writing some XML documentation for a predicate helper class. But I can't figure out
Writing a Service that is running on IIS. Basically looks like this: void ProcessRequest(HttpContext
Writing something like this using the loki library , typedef Functor<void> BitButtonPushHandler; throws a
I would like to do this: class Derived; class Base { virtual Derived f()
By default Html.ValidationSummary() produces HTML like this: <span class=validation-summary-errors>There were some errors...</span> <ul class=validation-summary-errors>
Writing a class, how do I implement foo.send(item) ? __iter__ allows iterating over the
writing to a text file is working good...But my problem is text file is
Writing my first PHP Class and came across an issue, the following is my

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.