title: Repaint() doesn't refresh the board when table of coordinates is changing.
body: <p>I would ask about JPanel, and paintComonent. I want to create Ludo game with Pawns. I tried to intiialize, buttonPanel ( responsible for buttons )   in game class(responisble for whole logic ). Paint - for printing and Player for keeping players and Pawns. In class buttonPanel I create action listener with JButton called createDiceBtn for rolling dice and changing positions of players. In players I defined method move for moving trough an array of declared coordinates in method initCoords ( there is less coordinates than in loops but for less clutter ). I've created button, and I tried to repaint it in Game class. Indexes of array are changing but I am a little bit confused with using repaint because it isn't work. Generally  I have problem with such behaviour [ Class game is keeping Paint class and Button Panel. Logic is in Game. If I press button with logic in game this will be repainted in Paint Class. What is the reason for this ? Ps. Sory for non-encaptulasion, firstly I would like it to work. </p>
  
  <p>Player</p>
  
  <pre><code>    package proj2;
  
  import java.util.Random;
  
  public class Player {
  
      public boolean active;
  
       Paw[] PawYellow;
       Paw[] PawRed;
       Paw[] PawBlue;
       Paw[] PawGreen;
      public Colors color;
      public Game game;
      ButtonPanel buttonPanel;
    //  public Game game;
  
      private Colors[]colors=Colors.values(); // enum of colors. 
  
      public Player() {
          this.active=active; //variable for chceking if this field is active. 
  
           PawYellow=new Paw[49];
           PawRed=new Paw[49];
           PawBlue=new Paw[49];
           PawGreen=new Paw[49];
           initCords();
      }
  
      public void move(int r,Paw paw[] )
      {
          //if (players.get(currentPlayer).equals(this.players.get(1))) {
          for (int i = 0; i &lt; 4; i++) {
              if (paw[i].is_active == true &amp;&amp; r == 6) {
                  paw[i] = paw[4];
                  paw[i].is_active = true;
                  paw[i].is_active = false;
                  System.out.println( paw[i].getX());
                  System.out.println( paw[i].getY());
                  paw[i].setX(paw[i].getX());
                  paw[i].setY(paw[i].getY());
                  buttonPanel.repaint();
  
                  break;
              }
          }
          for (int i = 4; i &lt; 49; i++) {
              if (paw[i].is_active == true) {
                  paw[i] = paw[i + r];
                  paw[i].is_active = false;
                  paw[i + r].is_active = true;
                  System.out.println( paw[i].getX());
                  System.out.println( paw[i].getY());
                  paw[i].setX(paw[i].getX());
                  paw[i].setY(paw[i].getY());
                //  buttonPanel.repaint();
                  break;
              }
          }
      }
  
      public void initCords() {
          PawYellow[0] = new Paw(140, 700, true);
          PawYellow[1] = new Paw(200, 700, true);
          PawYellow[2] = new Paw(140, 640, true);
          PawYellow[3] = new Paw(200, 640, true);
          PawYellow[4] = new Paw(380, 700, false);
          PawYellow[5] = new Paw(380, 635, false);
          PawYellow[6] = new Paw(380, 570, false);
          PawYellow[7] = new Paw(380, 505, false);
          PawYellow[8] = new Paw(380, 505, false);
          PawYellow[9] = new Paw(380, 440, false);
          PawYellow[10] = new Paw(320, 440, false);
          PawYellow[11] = new Paw(260, 440, false);
  
          PawRed[0] = new Paw(140, 50, true);
          PawRed[1] = new Paw(200, 110, true);
          PawRed[2] = new Paw(140, 110, true);
          PawRed[3] = new Paw(200, 50, true);
          PawRed[4] = new Paw(140, 310, false);
          PawRed[5] = new Paw(200, 310, false);
          PawRed[6] = new Paw(260, 310, false);
          PawRed[7] = new Paw(320, 310, false);
          PawRed[8] = new Paw(380, 310, false);
          PawRed[9] = new Paw(380, 245, false);
          PawRed[10] = new Paw(380, 180, false);
          PawRed[11] = new Paw(380, 115, false);
  
          PawBlue[0] = new Paw(740, 50, true);
          PawBlue[1] = new Paw(740, 110, true);
          PawBlue[2] = new Paw(680, 110, true);
          PawBlue[3] = new Paw(680, 50, true);
  
          PawBlue[4] = new Paw(500, 115, false);
          PawBlue[5] = new Paw(500, 180, false);
          PawBlue[6] = new Paw(500, 245, false);
          PawBlue[7] = new Paw(500, 310, false);
          PawBlue[8] = new Paw(560, 310, false);
          PawBlue[9] = new Paw(620, 310, false);
          PawBlue[10] = new Paw(680, 310, false);
          PawBlue[11] = new Paw(740, 310, false);
  
          PawGreen[0] = new Paw(740, 700, true);
          PawGreen[1] = new Paw(740, 640, true);
          PawGreen[2] = new Paw(680, 700, true);
          PawGreen[3] = new Paw(680, 640, true);
          PawGreen[4] = new Paw(740, 440, false);// start
          PawGreen[5] = new Paw(680, 440, false);
          PawGreen[6] = new Paw(620, 440, false);
          PawGreen[7] = new Paw(560, 440, false);
          PawGreen[8] = new Paw(500, 440, false);
          PawGreen[9] = new Paw(500, 505, false);
          PawGreen[10] = new Paw(500, 570, false);
          PawGreen[11] = new Paw(500, 635, false);
  
      }
  }
  
   class Paw {
          int x;int y; boolean is_active;
  
          public Paw(int x, int y, boolean is_active) {
              this.x = x;
              this.y = y;
              this.is_active = is_active;
          }
  
          public int getX() {
              return x;
          }
  
          public void setX(int x) {
              this.x = x;
          }
  
          public int getY() {
              return y;
          }
  
          public void setY(int y) {
              this.y = y;
          }
  
          public boolean isIs_active() {
              return is_active;
          }
  
          public void setIs_active(boolean is_active) {
              this.is_active = is_active;
          }
  
  }
  
  ///////////////////////////////////////////////////////////////////////////////////////////////////
  </code></pre>
  
  <p>//   Game. </p>
  
  <pre><code>package proj2;
  
  import javax.swing.*;
  import java.awt.*;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Map;
  import java.util.Scanner;
  
  public class Game {
      public Paw[] crdGreen;
      public Paw[] crdBlue;
      public Paw[] crdRed;
      public Paw[] crdYellow;
      List&lt;Player&gt; players = new ArrayList&lt;&gt;();
  
      public Player play1;
      public Player play2;
      public Player play3;
      public Player play4;
      public int currentPlayer = 0;
  
      ButtonPanel buttonPanel;
  
  
      public Game() {
  
          play1 = new Player();
          play2 = new Player();
          play3 = new Player();
          play4 = new Player();
      }
  
      public static void main(String[] args) {
          SwingUtilities.invokeLater(new Runnable() {
              @Override
              public void run() {
  
                  createAndShowGUI();
              }
          });
      }
  
      private static void createAndShowGUI() {
  
          Game g = new Game();
          Paint paint = new Paint(g);
          Board board = new Board();
          ButtonPanel buttonPanel = new ButtonPanel(paint, g);
          g.buttonPanel = buttonPanel;
  
          JFrame.setDefaultLookAndFeelDecorated(true);
          JFrame frame = new JFrame("Drawss On Image");
          frame.setSize(1400, 900);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.getContentPane().add(paint);
          frame.getContentPane().add(buttonPanel, BorderLayout.EAST);
          // frame.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
          frame.pack();
          frame.setLocationRelativeTo(null);
          frame.setVisible(true);
  
          g.initPlayers();
      }
  
      public void initPlayers() {
  
          Player play1 = new Player();
          play1.color = Colors.Green;
          this.players.add(play1);
  
          Player play2 = new Player();
          play2.color = Colors.Blue;
          this.players.add(play2);
  
          Player play3 = new Player();
          play3.color = Colors.Red;
          this.players.add(play3);
  
          Player play4 = new Player();
          play4.color = Colors.Yellow;
          this.players.add(play4);
  
  }
  
      public void diceResult(int r) {
  
          if (r != 6) {
  
              currentPlayer++;
              if (currentPlayer == (players.size())) {
                  currentPlayer = 0;
  
              }
  
          }
  
          if (players.get(currentPlayer).equals(this.players.get(0))) {
              players.get(0).move(r,play1.PawGreen);
              }
  
           else if (players.get(currentPlayer).equals(this.players.get(1))) {
              players.get(1).move(r,play2.PawBlue);
              }
  
          else  if (players.get(currentPlayer).equals(this.players.get(2))) {
              play3.move(r,play3.PawRed);
              }
          else  if (players.get(currentPlayer).equals(this.players.get(3))) {
              play4.move(r,play4.PawYellow);
          }
  
  buttonPanel.repaint();
  
      }
  
  ///////////////////////////////////////////////////////////////
  Button panel 
  package proj2;
  
  import javax.swing.*;
  import java.awt.*;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.util.concurrent.ThreadLocalRandom;
  
  public class ButtonPanel extends JPanel implements ActionListener {
      private Paint paint;
      final Dice dice = new Dice();
      JButton diceBtn = new JButton("Throw Dice");
      public Game game;
  
      int temp;
  
      public ButtonPanel(Paint paint, Game g) {
          this.paint = paint;
          game = g;
          add(createDiceBtn());
      }
  
      public JButton getDiceBtn() {
          return diceBtn;
      }
  
      public JButton createDiceBtn() {
          JButton diceBtn = new JButton();
          JButton diceBtn1 = new JButton();
          diceBtn.setBackground(Color.BLUE);
          diceBtn.addActionListener(this);
          //        //        //  diceBtn.s
          diceBtn.addActionListener(new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                  int r = dice.randomGenerator(); // method for rolling a dice
  
                  diceBtn.setText(" Wylosowano: " + r+ "Obecny gracz:" +game.currentPlayer);
  
                  game.diceResult(r);
              }
  
          });
          return diceBtn;
      }
  
      @Override
      public void actionPerformed(ActionEvent e) {
  
      }
  }
  
  /////////////////////////////////////////////////
  </code></pre>
  
  <p>Paint. 
      package proj2;</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  import java.awt.image.BufferedImage;
  
  public class Paint extends JPanel {
      Paint paint;
      ButtonPanel buttonPanel;
      Game game;
  
      public Paint(Game g)
      {
          game=g;
      }
  
      @Override
      public void paintComponent(Graphics g) {
         // super.paintComponent(g);
          g.setColor(Color.BLACK);
          g.drawOval(380, 635, 40, 40);
          g.drawOval(380, 570, 40, 40);
          g.drawOval(380, 505, 40, 40);
          g.drawOval(380, 440, 40, 40);
          g.drawOval(380, 310, 40, 40);
          g.drawOval(380, 245, 40, 40);
          g.drawOval(380, 180, 40, 40);
          .......
          /// way of painting static board. 
  
          // /////////////////
          // repainting on this board my pawns on 4 first positions
          Color customColor = new Color(0,102,0);
          g.setColor(customColor);
          g.fillOval( game.play1.PawGreen[0].getX(), game.play1.PawGreen[0].getY(),20,20);
          g.fillOval( game.play1.PawGreen[1].getX(), game.play1.PawGreen[1].getY(),20,20);
          g.fillOval( game.play1.PawGreen[2].getX(), game.play1.PawGreen[2].getY(),20,20);
          g.fillOval( game.play1.PawGreen[3].getX(), game.play1.PawGreen[3].getY(),20,20);
  
          Color customColor1 = new Color(102,0,0);
          g.setColor(customColor1);
          g.fillOval( game.play1.PawRed[0].getX(), game.play1.PawRed[0].getY(),20,20);
          g.fillOval( game.play1.PawRed[1].getX(), game.play1.PawRed[1].getY(),20,20);
          g.fillOval( game.play1.PawRed[2].getX(), game.play1.PawRed[2].getY(),20,20);
          g.fillOval( game.play1.PawRed[3].getX(), game.play1.PawRed[3].getY(),20,20);
  
          Color customColor2 = new Color(0,0,102);
          g.setColor(customColor2);
          g.fillOval( game.play1.PawBlue[0].getX(), game.play1.PawBlue[0].getY(),20,20);
          g.fillOval( game.play1.PawBlue[1].getX(), game.play1.PawBlue[1].getY(),20,20);
          g.fillOval( game.play1.PawBlue[2].getX(), game.play1.PawBlue[2].getY(),20,20);
          g.fillOval( game.play1.PawBlue[3].getX(), game.play1.PawBlue[3].getY(),20,20);
  
          Color customColor3 = new Color(255,204,0);
          g.setColor(customColor3);
          g.fillOval( game.play1.PawYellow[0].getX(), game.play1.PawYellow[0].getY(),20,20);
          g.fillOval( game.play1.PawYellow[1].getX(), game.play1.PawYellow[1].getY(),20,20);
          g.fillOval( game.play1.PawYellow[2].getX(), game.play1.PawYellow[2].getY(),20,20);
          g.fillOval( game.play1.PawYellow[3].getX(), game.play1.PawYellow[3].getY(),20,20);
  
  }
  </code></pre>