Estou com um problema novo…
Eu tenho uma malha de pontos e preciso que o ponto apontado pelo mouse seja destacado, e preciso que isso seja dinâmico, tentei fazer um código pra isso, acho que cheguei perto, mas o “destaque” do ponto não some, fica lá e se eu passar por 10 pontos os 10 ficarão destacados Y_Y
[code]import java.awt.Color;
import java.awt.Graphics;
import java.awt.Point;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.JApplet;
public class NewJApplet extends JApplet {
Point malha[][];
Point area;
Point foco;
int k;
int l;
@Override
public void init() {
area = new Point();
foco = new Point(-1, -1);
carregaMalha(10);
addMouseMotionListener(new MouseAdapter() {
@Override
public void mouseMoved(MouseEvent e) {
foco.setLocation(-1, -1);
for (int i = 0; i < k; i++)
if (e.getX() == malha[i][0].x){
for (int j = 0; j < l; j++)
if (e.getY() == malha[i][j].y){
foco.setLocation(e.getX(), e.getY());
}
}
repaint();
}
});
}
@Override
public void paint(Graphics g){
for (int i = 0; i <k; i++){
for (int j = 0; j < l; j++){
g.drawOval((malha[i][j].x -1), (malha[i][j].y -1), 1, 1);
}
}
if (foco.x > 0){
g.setColor(Color.red);
g.drawRect((foco.x -2), (foco.y -2), 4, 4);
g.setColor(Color.black);
}
}
private void carregaMalha(int passo){
area.x = this.getWidth();
area.y = this.getHeight();
k = area.x/passo;
l = area.y/passo;
malha = new Point[k][l];
for (int i=0; i<k; i++){
for (int j=0; j<l; j++){
malha[i][j] = new Point(i*passo, j*passo);
}
}
}
}[/code]
alguem sabe porquê isso ocorre?