Article View: borland.public.jbuilder.java.swing
Article #10800Re: Adding global mouse listener
From: Andrew J Azzinaro
Date: Wed, 11 Aug 1999 00:00
Date: Wed, 11 Aug 1999 00:00
103 lines
3572 bytes
3572 bytes
Another solution, though maybe not as elegant would be to "replace" the
system queue
with your own. This way you can watch for an event (MouseMoved,
MouseClicked...ect)
and do what you need to. The nice thing is you will get it first and can do
something before passing the event on.
This has not been tested for thread safety and a hashtable would probably be
a better data structure to store the ID in. It should be enough to get you
started....
example:
public class EventQueueWatcher extends EventQueue
{
protected Vector eventsToWatch = new Vector();
protected void dispatchEvent(AWTEvent event)
{
printEvent (event); // Do what you want with the event.
super.dispatchEvent(event); // pass it on to the super class to "handle"
}
private void printEvent (AWTEvent e)
{
if (eventsToWatch.contains(new Long (e.getID())))
{
System.out.println (e.toString());
}
}
public void addEventWatch (Long i)
{
if (!eventsToWatch.contains(i))
{
eventsToWatch.addElement(i);
}
}
public void removeEventWatch (Long i)
{
eventsToWatch.removeElement(i);
}
/* public static void main(String[] args)
EventQueueWatcher q = new EventQueueWatcher ();
q.addEventWatch (new Long(MouseEvent.MOUSE_CLICKED));
// or another mouse event (MOVED, DRAGGED....)
JFrame frame = new JFrame();
frame.getToolkit().getSystemEventQueue().push(q);
frame.setSize(300,300);
frame.setVisible(true);
} */
}
Matt Krevs <mattkrevs@bigpond.com.au> wrote in message
news:7oqejc$b197@forums.borland.com...
> This _might_ work
>
> Add a ContainerListener to your top level window(s)
>
> Whenever a component is added you will be notified.
>
> Add your class as a MouseListener to all components that are added
>
> Maybe a better way would be to make all components that are 'help enabled'
> to implement an interface, lets call it IHelpEnabled.
>
> That way you can configure it so that your help class only registers as a
> MouseListener to all objects implementing the IHelpEnabled interface.
>
> This interface could have one method called String getHelpText() or
> something.
>
>
> Jason Burton <Jason.Burton@McLeodSoftware.com> wrote in message
> news:7opsfj$ala3@forums.borland.com...
> > Does anyone know of a way to track mouse events at the application
level?
> > For example, I want the user to be able to click a "Help" button. This
> > changes their cursor into a question mark. I want my Help class to then
> > listen to mouse events to display context sensitive help the next time
the
> > mouse is clicked (at which time the Help class will quit listening to
> mouse
> > events).
> >
> > Any ideas?
> >
> > Jason
> >
> >
>
>
Technical Details
Message-ID:
<7osb2u$cqg8@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<7opsfj$ala3@forums.borland.com> <7oqejc$b197@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,2c6fb04c8324bda4 X-Google-Attributes: gid111d45,public From: "Andrew J Azzinaro" <aazzinaro@home.com> Subject: Re: Adding global mouse listener Date: 1999/08/11 Message-ID: <7osb2u$cqg8@forums.borland.com> X-Deja-AN: 511511841 References: <7opsfj$ala3@forums.borland.com> <7oqejc$b197@forums.borland.com> X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2314.1300 Organization: Another Netscape Collabra Server User X-MSMail-Priority: Normal Newsgroups: borland.public.jbuilder.java.swing