title: Coding a game of Pool in Java - how can I define the balls and move them (via Graphics g)?
body: <p>My plan is to design a simple game of Pool in Java.</p>
  
  <p>OOP makes the most sense here for the balls. All the balls have the same functionality, so because of that it would be a good idea to make a Ball class that would handle the relative position of the ball and other variables such as when it goes in a hole it removes itself and increments your score. So when it hits a hole Ball.dispose (); would fit nicely. </p>
  
  <p>My issue is that I do not know how to manipulate the ball and dispose of it. Also inorder to  move it I rely on Thread.sleep instead of java.swing.timer because there is no available Action Performed method I can rely on. </p>
  
  <p><strong>How can I move the ball more easily and get rid of it when needed?</strong></p>
  
  <p><img src="https://i.stack.imgur.com/lh3Pn.png" alt="enter image description here"></p>
  
  <p><strong>The green thing covering the ball is my way of erasing the last position of the ball by drawing a green oval over it.</strong></p>
  
  <pre><code>import java.awt.Color;
  import java.awt.Graphics;
  import javax.swing.JFrame;
  
  
  public class Main extends JFrame{
  
       Ball redball = new Ball (285, 600, 20, 20, Color.RED); 
  
      //variables to control redball
      private int rX = redball.getX();
      private int rY = redball.getY();
      private final int rWidth = redball.getWidth();
      private final int rHeight = redball.getHeight();
  
      int Force = 30; 
      int Bearing = 20; // True Bearing
  
   public Main (){
  
           setSize(600, 800);
           setVisible(true); 
           setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
           setTitle("Pool");
  
      }
       public void paint(Graphics g){
           super.paint(g);
  
           // draw the table
           g.setColor (Color.GREEN);
           g.fillRect(100, 100, 400, 600);
           g.setColor (Color.BLACK);
           g.drawRect(99, 99, 401, 601);
  
  
               //draw start ball
           g.setColor(redball.getColor());
           g.fillOval(rX, rY, rWidth, rHeight);
  
  
  
           if (Force == 30){
           for (int i = Force; i &gt; 0;i--){
               try {
                      Thread.sleep(100);
                  } catch(InterruptedException ex) {
                      Thread.currentThread().interrupt();
                  }
               Force--;
               if (rY &gt; 98 + rWidth) {
                   rY = rY - i;
                   rX = rX + (Bearing/5);
               }
  
               g.fillOval(rX, rY, rWidth, rHeight);
               g.setColor(Color.GREEN);
               repaint ();
               g.fillOval(rX - (Bearing/5), rY + i, rWidth, rHeight); // repaint last ball
               g.setColor(Color.RED);
               repaint ();
            }
           }
  
  
  
           // Ball.dispose (redball);
  
       }
  
      public static void main(String[] args) {
  
          new Main();
      }
  </code></pre>
  
  <p><strong>Here is the class for the ball</strong></p>
  
  <pre><code>public class Ball {
  
      private int x;
      private int y;
      private int width;
      private int height;
      private Color color;
  
      public Ball (int x, int y, int width, int height, Color color)
      {
      this.x = x;
      this.y = y;
      this.width = width;
      this.height = height;
      this.color = color;
      }
  
      public void setX (int x){
          this.x = x;
      }
  
      public int getX (){
          return this.x;
      }
  
      public void setY (int x){
          this.y = y;
      }
  
      public int getY (){
          return this.y;
      }
  
      public void setWidth (int width){
          this.width = width;
      }
  
      public int getWidth (){
          return this.width;
      }
  
      public void setHeight (int height){
          this.height = height;
      }
  
      public int getHeight (){
          return this.height;
      }
  
      public void setColor (Color color){
          this.color = color;
      }
  
      public Color getColor (){
          return this.color;
      }
  
      public static void dispose(Ball ball) {
  
      ball = null; // if I call this method nothing happens
  
      }
  
  
  }
  </code></pre>