I have a map applet, and I have JLabel after the mouse, whenever the mouse moves around the city, JLable displays the name of the city and population.
I use the mouseMotionListener MouseMoved method for this, but I want the label to be there only if the mouse stays a couple of seconds above the city.
I donโt know if this was due to the fact that I worked on this code for several days, but I canโt think of a solution for this using the MouseMoved method, I tried to use timers, but this did not help me (mayb, I just did it wrong because my brain burned out)
so is there a mouse to listen to the mouse? or do you have any recommendations?
here is more or less what i got
public void mouseMoved(MouseEvent evt) { int x = evt.getX(); int y = evt.getY(); boolean aboveCity = false; mouseover.setBounds(x+20, y-10, 200, 20); //mouseover is a JLabel for (int i=0;i<cityCounter;i++){ if (city[i].containsPoint(x,y){ name = city[i].getName(); population = city[i].getPopulation(); aboveCity = true; } } if(aboveCity){ mouseover.setText(name + ", " + population); } else{ mouseover.setText(""); } }
source share