Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Java Code Help on Draw method

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    1
    My Mood
    Sleepy
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java Code Help on Draw method

    I am trying to do the Pong Lab in Dr. Java from A+ Computer Science. I am finished doing everything, however, when I run the game the ball leaves a trail behind. I do not know how to get rid of it and any help would be greatly appreciated. As of right now this is my draw method for the ball. I am drawing the ball blue and the trail should be white as to cover it. The ball being drawn blue is in another method. I just need this to get rid of the ball's trail.
    public void moveAndDraw(Graphics window)
    {
    //draw a white ball at old ball location
    draw(window,Color.WHITE);

    draw(window,Color.WHITE);//draws over the old ball with whichever color you want
    //in case you want to have a trail

    setX(getX()+xSpeed);
    setY(getY()+ySpeed);

    //setY

    draw(window); //draws the ball at its new location
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Java Code Help on Draw method

    Can you make a small, simple program that compiles, executes and show the problem.

    Are you calling the paint method's super to clear the old drawings?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Help ! merge this code into 1 main method . ASAP :( tnx
    By anitsirc in forum Object Oriented Programming
    Replies: 2
    Last Post: November 23rd, 2011, 11:53 AM
  2. Change the random draw line here for a mouseListener draw
    By Panda23 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 10th, 2011, 03:29 AM
  3. Should validation code exist in set methods or in a validate method
    By mydarkpassenger in forum Java Theory & Questions
    Replies: 4
    Last Post: May 27th, 2010, 08:37 AM
  4. Java Code Help - Calling Method
    By KevinGreen in forum Object Oriented Programming
    Replies: 5
    Last Post: September 18th, 2009, 12:55 AM
  5. adding main method to a code
    By IDK12 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: August 31st, 2009, 08:52 PM

Tags for this Thread