timing the mouse events
1 posts in topic
Flat View  Flat View

Posted By:   Andreea_Francu
Posted On:   Monday, April 30, 2001 01:26 PM

I'm working on an editor where one can draw basic shapes on the canvas. For every shape I'm providing a "note" window (kind of like the notes in Excel) where one can type more information about the shape. In the current implementation the notes pop up when one slides the mouse over the shape (all the code is in the mouseMoved method). I want to change this feature such that the the window appears only after the user has kept the mouse over that shape for a few seconds.
Any idea how I can do that?

Re: timing the mouse events

Posted By:   Sandip_Chitale  
Posted On:   Monday, April 30, 2001 09:41 PM

Add a MouseListener to the shape (assuming that shape is a subclass of component). Else you will have to implement the equivalent using the
MouseMotionListener on the component on
which the shape is drawn. For arbitrary shapes detecting if the mouse is
inside or outside could be very complex. I think Java2D has special methods for it.

Start a timer in the mouseEntered callback. User the javax.swing.Timer
class for that.

public Timer(int delay,
ActionListener listener)

If the timer expires
it will call the ActionListener's
actionPerformed(...) method. Show your
notes windows here.

If the mouseExited(...) is called before the timer expires cancel the timer.

About | Sitemap | Contact