title: Java circular frame Ball Animation
body: <p>I'm new to java. I am like to create a simple animation with a ball moving from left to right and i wish to give it an circular frame illusion(i don't know how to phrase it) If part of the ball leave the border of the frame(right side), that part would reappear in the left side of my frame. I had no idea how to start. So far i only manage to get the ball move. </p>
  
  <p>This is a part of my code </p>
  
  <pre><code>public class BallAnimation extends JFrame {
  
  
  private JButton left,right,up,down;
  private Balls ball = new Balls();
  private Ellipse2D circle;
  
  public BallAnimation()
  {
      add(ball);
  }
  
  public class Balls extends JPanel{
  
  private double X=0,Y=0;
  private int i=1;
  public void paintComponent(Graphics g)
  {
      super.paintComponent(g);
      Graphics2D g2 = (Graphics2D) g;
      g.setColor(Color.CYAN);
      g.fillRect(0, 0, getWidth(), (getHeight()));
  
      if(X==0 &amp;&amp; Y ==0)
      {
      X=getWidth()/2.1;
      Y=getHeight()/2.3;
      g.setColor(Color.RED);
      circle= new Ellipse2D.Double(X,Y,50,50);
      g2.fill(circle);
      }
      else
      {
          g.setColor(Color.RED);
          circle= new Ellipse2D.Double(X,Y,50,50);
          g2.fill(circle);
      }
      if(i==1)
      {
          X=X+10;
          try {
              Thread.sleep(100);
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
          repaint();
      }
  
  }
  }
  
  public static void main(String[] args)
  {
      BallAnimation test = new BallAnimation();
      test.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      test.setSize(700,500);
      test.setVisible(true);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I'd search around and didn't find anything, maybe the phrase im use is not right. Any help would be appreciated. </p>