title: Can't move pieces properly with mousePressed
body: <p>If i do the code like this, it only works one time, i cant do other move and i know the error is all in the mousePressed function, but i can't solve it:
  The problem is specifically here:</p>
  <pre><code>public void mousePressed(MouseEvent me) {
      if(foi==false) {
          posxmouse = me.getX()/100;
          posymouse = me.getY()/100;
          foi = true;
      }
      if(foi==true) {
          posx1mouse = me.getX()/100;
          posy1mouse = me.getY()/100;
          System.out.println(&quot;posx: &quot; + me.getX()/100);
          System.out.println(&quot;posy: &quot; + me.getY()/100);
          board = moves.MajorMovePawn(board, posymouse, posxmouse, posy1mouse, posx1mouse);
      }
  </code></pre>
  <p>But this is the fully code, and i hope you guys have the solution for a so simple problem like this.
  I'm brazilian, the word &quot;foi&quot; means something like &quot;done&quot;, and i used it to catch the two coordinates of the mouse and move one piece and after exclude the position where the piece was originally.</p>
  <pre><code>import java.awt.Color;
  import java.awt.Dimension;
  import java.awt.Graphics;
  import java.awt.Graphics2D;
  import java.awt.Image;
  import java.awt.event.MouseEvent;
  import java.awt.event.MouseListener;
  import javax.swing.ImageIcon;
  import javax.swing.JPanel;
  
  /**
   *
   * @author Pedro Maxx
   */
  public class Game extends JPanel implements MouseListener {
      public Moves moves = new Moves();
      public String[][] initialboard = { 
              { &quot;TB&quot;, &quot;HB&quot;, &quot;BB&quot;, &quot;KB&quot;, &quot;QB&quot;, &quot;BB&quot;, &quot;HB&quot;, &quot;TB&quot; },
              { &quot;PB&quot;, &quot;PB&quot;, &quot;PB&quot;, &quot;PB&quot;, &quot;PB&quot;, &quot;PB&quot;, &quot;PB&quot;, &quot;PB&quot; }, 
              { &quot;V&quot;, &quot;V&quot;, &quot;V&quot;, &quot;V&quot;, &quot;V&quot;, &quot;V&quot;, &quot;V&quot;, &quot;V&quot; },
              { &quot;V&quot;, &quot;V&quot;, &quot;V&quot;, &quot;V&quot;, &quot;V&quot;, &quot;V&quot;, &quot;V&quot;, &quot;V&quot; }, 
              { &quot;V&quot;, &quot;V&quot;, &quot;V&quot;, &quot;V&quot;, &quot;V&quot;, &quot;V&quot;, &quot;V&quot;, &quot;V&quot; },
              { &quot;V&quot;, &quot;V&quot;, &quot;V&quot;, &quot;V&quot;, &quot;V&quot;, &quot;V&quot;, &quot;V&quot;, &quot;V&quot; }, 
              { &quot;PW&quot;, &quot;PW&quot;, &quot;PW&quot;, &quot;PW&quot;, &quot;PW&quot;, &quot;PW&quot;, &quot;PW&quot;, &quot;PW&quot; },
              { &quot;TW&quot;, &quot;HW&quot;, &quot;BW&quot;, &quot;KW&quot;, &quot;QW&quot;, &quot;BW&quot;, &quot;HW&quot;, &quot;TW&quot; }, 
          };
      public boolean foi, move = false;
      public static boolean vezW = true, vezB = false, done;
      public boolean obst = false;
      public int posx, posy, posx1, posy1;
      public String[][] board = new String[8][8];
      public ImageIcon pawnB = new ImageIcon(&quot;ChessJava//PawnBlack.png&quot;),
              pawnW = new ImageIcon(&quot;ChessJava//PawnWhite.png&quot;), towerB = new ImageIcon(&quot;ChessJava//TowerBlack.png&quot;),
              towerW = new ImageIcon(&quot;ChessJava//TowerWhite.png&quot;), horseB = new ImageIcon(&quot;ChessJava//HorseBlack.png&quot;),
              horseW = new ImageIcon(&quot;ChessJava//HorseWhite.png&quot;), bishopB = new ImageIcon(&quot;ChessJava//BishopBlack.png&quot;),
              bishopW = new ImageIcon(&quot;ChessJava//BishopWhite.png&quot;), queenB = new ImageIcon(&quot;ChessJava//QueenBlack.png&quot;),
              queenW = new ImageIcon(&quot;ChessJava//QueenWhite.png&quot;), kingB = new ImageIcon(&quot;ChessJava//KingBlack.png&quot;),
              kingw = new ImageIcon(&quot;ChessJava//KingWhite.png&quot;);
      public Image imgPawnB = pawnB.getImage(), imgPawnW = pawnW.getImage(), imgTowerB = towerB.getImage(),
              imgTowerW = towerW.getImage(), imgHorseB = horseB.getImage(), imgHorseW = horseW.getImage(),
              imgBishopB = bishopB.getImage(), imgBishopW = bishopW.getImage(), imgQueenB = queenB.getImage(),
              imgQueenW = queenW.getImage(), imgKingB = kingB.getImage(), imgKingW = kingw.getImage();
      public int movesPawn2 = 2, movesPawn1 = 1, posxmouse = 0, posymouse = 0, posx1mouse = 0, posy1mouse = 0;;
  
      public Game() {
          setFocusable(true);
          setPreferredSize(new Dimension(800, 800));
          addMouseListener(this);
          setInicio();
      }
  
      public void setInicio() {
          for (int conti = 0; conti &lt; 8; conti++) {
              for (int contij = 0; contij &lt; 8; contij++) {
                  board[conti][contij] = initialboard[conti][contij];
              }
          }
      }
  
      public void paintComponent(Graphics g) {
          Graphics2D grafico = (Graphics2D) g;
          super.paintComponent(g);
          //Cria o tabuleiro: 
          for (int i = 0; i &lt; 8; i++) {
              for (int j = 0; j &lt; 8; j++) {
                  if ((i + j) % 2 == 0) {
                      g.setColor(Color.white);
                  } else {
                      g.setColor(Color.GREEN);
                  }
                  grafico.fillRect(j * 100, i * 100, 100, 100);
              }
          }
          for (int i = 0; i &lt; 8; i++) {
              for (int j = 0; j &lt; 8; j++) {
                  if (board[i][j].equals(&quot;PB&quot;)) {
                      grafico.drawImage(imgPawnB, (j * 100), (i * 100 + 10), null);
                  }
                  if (board[i][j].equals(&quot;PW&quot;)) {
                      grafico.drawImage(imgPawnW, (j * 100), (i * 100 + 10), null);
                  }
                  if (board[i][j].equals(&quot;BB&quot;)) {
                      grafico.drawImage(imgBishopB, (j * 100), (i * 100 + 10), null);
                  }
                  if (board[i][j].equals(&quot;BW&quot;)) {
                      grafico.drawImage(imgBishopW, (j * 100), (i * 100 + 10), null);
                  }
                  if (board[i][j].equals(&quot;TB&quot;)) {
                      grafico.drawImage(imgTowerB, (j * 100), (i * 100 + 10), null);
                  }
                  if (board[i][j].equals(&quot;TW&quot;)) {
                      grafico.drawImage(imgTowerW, (j * 100), (i * 100 + 10), null);
                  }
                  if (board[i][j].equals(&quot;HB&quot;)) {
                      grafico.drawImage(imgHorseB, (j * 100), (i * 100 + 10), null);
                  }
                  if (board[i][j].equals(&quot;HW&quot;)) {
                      grafico.drawImage(imgHorseW, (j * 100), (i * 100 + 10), null);
                  }
                  if (board[i][j].equals(&quot;QB&quot;)) {
                      grafico.drawImage(imgQueenB, (j * 100), (i * 100 + 10), null);
                  }
                  if (board[i][j].equals(&quot;QW&quot;)) {
                      grafico.drawImage(imgQueenW, (j * 100), (i * 100 + 10), null);
                  }
                  if (board[i][j].equals(&quot;KB&quot;)) {
                      grafico.drawImage(imgKingB, (j * 100), (i * 100 + 10), null);
                  }
                  if (board[i][j].equals(&quot;KW&quot;)) {
                      grafico.drawImage(imgKingW, (j * 100), (i * 100 + 10), null);
                  }
              }
          }
          repaint();
      }
  
      @Override
      public void mousePressed(MouseEvent me) {
          if (foi == false) {
              posxmouse = me.getX() / 100;
              posymouse = me.getY() / 100;
              foi = true;
          }
          if (foi == true) {
              posx1mouse = me.getX() / 100;
              posy1mouse = me.getY() / 100;
              System.out.println(&quot;posx: &quot; + me.getX() / 100);
              System.out.println(&quot;posy: &quot; + me.getY() / 100);
              board = moves.MajorMovePawn(board, posymouse, posxmouse, posy1mouse, posx1mouse);
          }
      }
  
      @Override
      public void mouseReleased(MouseEvent me) {
      }
  
      @Override
      public void mouseClicked(MouseEvent me) {
      }
  
      @Override
      public void mouseEntered(MouseEvent me) {
      }
  
      @Override
      public void mouseExited(MouseEvent me) {
      }
  
      public String testPiece(int posypiece, int posxpiece) {
          String piece = &quot;&quot;;
          // Testar se é um peão branco
          if (board[posypiece][posxpiece].equals(&quot;PW&quot;)) {
              piece = &quot;PW&quot;;
              System.out.println(&quot;É um peão branco!&quot;);
          }
          // Testar se é um peão preto: 
          if (board[posypiece][posxpiece].equals(&quot;PB&quot;)) {
              piece = &quot;PB&quot;;
              System.out.println(&quot;É um peão preto!&quot;);
          }
          return piece;
      }
  
      public boolean movePawnWhite(int posypawn, int posxpawn, int posypawn1, int posxpawn1) {
          boolean pode = true;
          if (testPiece(posypawn, posxpawn).equals(&quot;PW&quot;)) {
              if (!board[posypawn - 1][posxpawn].equals(&quot;V&quot;)) {
                  pode = false;
              }
              if (!board[posypawn - 2][posxpawn].equals(&quot;V&quot;)) {
                  pode = false;
              }
          }
          return pode;
      }
  }
  </code></pre>
  <p>Honestly, i think there's no issue with the Moves class:</p>
  <pre><code>public class Moves {
      public int boardaux[][] = new int[8][8];
  
      public String[][] MajorMovePawn(String board[][], int posy, int posx, int posy1, int posx1) {
          String[][] boardFinal = board;
          if(boardFinal[posy][posx].equals(&quot;PW&quot;)) {
              System.out.println(board[posy][posx]);
              if(board[posy1][posx1].equals(&quot;V&quot;)) {
                  boardFinal[posy1][posx1] = &quot;PW&quot;;
                  boardFinal[posy][posx] = &quot;V&quot;;
              }
          }
          return boardFinal;
      }
  }
  </code></pre>