Advertisement
Tech_geek23

BallTestTwo.java

Feb 28th, 2013
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.02 KB | None | 0 0
  1. import java.awt.Color;
  2. import java.awt.Graphics;
  3. import java.awt.Graphics2D;
  4. import java.awt.Canvas;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7.  
  8. class BallTestTwo extends Canvas implements Runnable
  9. {
  10.     private Ball ball;
  11.  
  12.     public BallTestTwo()
  13.     {
  14.         setBackground(Color.WHITE);
  15.         setVisible(true);
  16.  
  17.         //instantiate a new Ball
  18.         Ball ba = new Ball();
  19.        
  20.         //test the Ball thoroughly
  21.        
  22.  
  23.         //test all constructors
  24.        
  25.        
  26.         new Thread(this).start();
  27.     }
  28.    
  29.     public void update(Graphics window)
  30.     {
  31.         paint(window);
  32.     }
  33.  
  34.     public void paint(Graphics window)
  35.     {
  36.         ball.moveAndDraw(window);
  37.  
  38.         if(!(ball.getX()>=10 && ball.getX()<=550))
  39.         {
  40.             ball.setXSpeed(-ball.getXSpeed());
  41.         }
  42.  
  43.         if(!(ball.getY()>=10 && ball.getY()<=450))
  44.         {
  45.             ball.setYSpeed(-ball.getYSpeed());
  46.         }
  47.     }
  48.    
  49.    public void run()
  50.    {
  51.     try
  52.     {
  53.         while(true)
  54.         {
  55.            Thread.currentThread().sleep(19);
  56.             repaint();
  57.          }
  58.       }catch(Exception e)
  59.       {
  60.       }
  61.     }  
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement