Results 1 to 3 of 3
  1. #1
    gryd00 is offline Member
    Join Date
    Apr 2011
    Rep Power

    Default help! bouncing ball program

    Im new to Java and im tryng to do animation. I copy the stanford bouncing ball so i can study it. i imported the acm package by right clicking on the project then properties ,java build, path,library and add the external jars. and added the acm.
    it happens to be ok. but when i run the program it gives me an empty applet. and debug message :confused:
    Thread [main](suspended(exeption NullPointerExeption))
    bounce.moveBall()l etc.......

    Could someone help me out here and tell me whats the problem? Keep in mind that I am very new to programming .. THanks in advance..

    here is the code:
    Java Code:
    import acm.program.*;
    public class bounce extends GraphicsProgram{
    private GOval ball; // this is the ball 
    private static final int ball_diam = 30; // ball diameter
    private static final double gravity = 3; // gravity
    private static final int delay = 50; // DELAY .5 SEC
    // ball start position 
    private static final double x_start = ball_diam / 2; // start position x
    private static final double y_start = 100; // start position for y
    // velocity 
    private static final double x_vel = 5;
    private static final double bounce_reduce = 0.9;
    // starting x and y velocity
    private double xVel = x_vel;
    private double yVel = 0.0;
    public void run(){
    // Create and Place the ball.
    private void setup(){
    	ball = new GOval (x_start, y_start, ball_diam, ball_diam);
    // update and move the ball.
    private void moveBall(){
    	yVel += gravity;
    // determine if collision with the floor, update velocities 
    // and location as appropriate
    private void checkForCollision(){
    	if (ball.getY() > getHeight()- ball_diam){
    		yVel = -yVel * bounce_reduce;		
    // assume bounce will move ball an amount above the floor
    // equal to the amount it would have dropped
    // below the floor
    double diff = ball.getY() - (getHeight() - ball_diam);
     ball.move(0, -2 * diff);
    Last edited by gryd00; 05-10-2011 at 08:50 AM.

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Richmond, Virginia
    Blog Entries
    Rep Power


    Please edit your post to have code tags around your code.

    To do this, type [code] before the first line of code, and [/code] after the last line


    It will look like this
    Java Code:

  3. #3
    gryd00 is offline Member
    Join Date
    Apr 2011
    Rep Power


    done with the edit... really appreciate for a help .. dont know why applet is not showing the ball that i wanted too.. but when i remove the set up and add the ball.. it appears but still no animation. sorry for my English.. thanks in advance..

Similar Threads

  1. Bouncing Ball program
    By lost1000 in forum New To Java
    Replies: 3
    Last Post: 11-18-2010, 04:26 PM
  2. Bouncing ball program... having problems..
    By ilovenayoon in forum Java Applets
    Replies: 1
    Last Post: 12-08-2009, 05:16 PM
  3. high bouncing ball
    By bouncingball in forum Reviews / Advertising
    Replies: 1
    Last Post: 06-19-2008, 12:21 PM
  4. bouncing ball issue
    By adam405 in forum New To Java
    Replies: 1
    Last Post: 03-18-2008, 04:48 AM
  5. Problem deleting ball from bouncing ball app
    By adlb1300 in forum New To Java
    Replies: 2
    Last Post: 12-03-2007, 10:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts