Results 1 to 2 of 2

Thread: bounce ball

  1. #1
    Pramod kulat is offline Member
    Join Date
    Oct 2013
    Posts
    1
    Rep Power
    0

    Default bounce ball

    import java.applet.*;
    import java.awt.*;
    /*
    <applet code="bounce" width=200 height=200>
    </applet>
    */

    public class bounce extends Applet implements Runnable
    {
    int x = 150, y = 50, r=20;
    int dx = 11, dy = 7;
    Thread t;
    boolean stopFlag;

    public void start()
    {
    t = new Thread(this);
    stopFlag=false;
    t.start();
    }
    public void paint(Graphics g)
    {
    g.setColor(Color.red);
    g.setBackground(Color.black);
    g.fillOval(x-r, y-r, r*2, r*2);
    }
    public void run()
    {
    while(true)
    {
    if(stopFlag)
    break;
    if ((x - r + dx < 0) || (x + r + dx > bounds().width)) dx = -dx;
    if ((y - r + dy < 0) || (y + r + dy > bounds().height)) dy = -dy;
    x += dx; y += dy;
    try
    {
    Thread.sleep(100);
    }catch(Exception e){};
    repaint();
    }
    }

    public void stop()
    {
    stopFlag=true;
    t=null;
    }
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,817
    Rep Power
    19

    Default Re: bounce ball

    Moved out of staff only section.

    Also, when posting code please wrap it in [code] tags [/code] in order to retain its formatting.
    Finally, you haven't actually asked a question.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Ball Bounce project
    By jwl in forum New To Java
    Replies: 4
    Last Post: 09-06-2012, 04:55 PM
  2. Not able to stored the bounce email
    By kumar11 in forum Apache Commons
    Replies: 0
    Last Post: 06-27-2012, 11:14 AM
  3. Problem deleting ball from bouncing ball app
    By adlb1300 in forum New To Java
    Replies: 2
    Last Post: 12-03-2007, 09:08 PM
  4. Bouncing Ball Just Suddenly Stops Mid Bounce
    By adlb1300 in forum Java 2D
    Replies: 1
    Last Post: 12-03-2007, 02:58 PM
  5. Replies: 2
    Last Post: 12-01-2007, 07:48 AM

Posting Permissions

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