The board is 500x500 and each square of it is 50px, so the variables NovaPosicaoX
and Y
always take the border of the square where the mouse pointer is.
The problem is that the relief only works in the squares of the window border, and when I move the mouse, this does not change. You have to take your mouse out of the window and get back to updating.
ImageIcon tabuleiro = new ImageIcon(getClass().getResource("tabuleiro.png"));
JLabel v = new JLabel(new ImageIcon(getClass().getResource("vazio.png")));
//Imagem que quero fazer o efeito de relevo ao passar o mouse sobre t
JLabel t = new JLabel(tabuleiro);
//Aqui seria o código onde coloco as posições de cada JLabel...
public void mouseEntered(MouseEvent arg0) {
double x = t.getMousePosition().getX();
double y = t.getMousePosition().getY();
int novaPosicaoX, novaPosicaoY;
novaPosicaoX = (int) x - (int)x % 50;
novaPosicaoY = (int) y - (int)y % 50;
v.setBounds(novaPosicaoX-3, novaPosicaoY, 50,50);
v.setVisible(true);
}
Override
public void mouseExited(MouseEvent arg0) {
v.setVisible(false);
}
The red area does not work.