title: JAVA moving a ball
body: <p>I have tried to make a program that on the screen the ball would move by itself. But the problem is that it doesn`t do repaint();</p>
  
  <p>Any suggestion how to fix it?</p>
  
  <p>(main class) Main.java: </p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  
  public class Main extends JFrame{
      static int x = 10;
  
  
      public static void main(String[] args){
          JFrame f = new JFrame("title");
          f.setVisible(true);
          f.setSize(300,250);
          f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          sekon m = new sekon();
          f.add(m);
  
          antr t = new antr();
          Thread th = new Thread(t);
          th.start();
      }
  }
  </code></pre>
  
  <p>(second class) sekon.java:</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  
  public class sekon extends JPanel{
      int xiu = 10;
  
      public void paintComponent(Graphics g){
          super.paintComponent(g);
          g.setColor(Color.RED);
          g.fillOval(xiu, 10, 20, 20);
  
      }
  
  
      public void changeX(int b){
          this.xiu = b;
      }
  
  
  
  }
  
       class antr extends JPanel implements Runnable{
           int xi = 10;
          sekon s = new sekon();
           public void run(){
  
               xi += 1;
               s.changeX(xi);
               JPanel p = new JPanel();
               p.repaint();
  
               try{
                   Thread.sleep(5);
                   }catch(Exception e){}
           }
      }
  </code></pre>