2
The board is 500x500 and each square of it is 50px, so the variables NovaPosicaoX
and Y
always take the edge of the square where ta the mouse pointer.
The problem is that the relief only works on the squares of the window edge, and when I pass the mouse, it doesn’t change. You have to take the mouse out of the window and come back to update.
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 area in red does not work.
the question was in the comment code, I edited now
– Taum