Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Query:is there the concept of priority level in java's event responsesystem?

Reply
Thread Tools

Query:is there the concept of priority level in java's event responsesystem?

 
 
Jack Dowson
Guest
Posts: n/a
 
      05-13-2007
Hello Everybody:
I am indulging in java's gui programing these days.
Yesterday,I created a tree using class JTree.I've tried two ways to
response TreeSelectEvent,one is by implementing interface
treeSelectionListener,the other is by MosueListener.
They both worked well when applied alone.But when I employed them both
at the same time,only MouseListener worked,so I think there might be
some concepts like priority level in java's event response system?
Am I right? Or there might have something else happened?

Thanks.
Dowson.
 
Reply With Quote
 
 
 
 
Tom Hawtin
Guest
Posts: n/a
 
      05-13-2007
Jack Dowson wrote:
> Yesterday,I created a tree using class JTree.I've tried two ways to
> response TreeSelectEvent,one is by implementing interface
> treeSelectionListener,the other is by MosueListener.
> They both worked well when applied alone.But when I employed them both
> at the same time,only MouseListener worked,so I think there might be
> some concepts like priority level in java's event response system?


AWT's MouseListener and MouseMotionListener handling is broken. This
causes many bugs and peculiar behaviour.

Unlike every other event, if a component has no mouse [motion] listener
then mouse events are bubbled up to the parent container. This means you
can get away with listening to a parent component, and still receive
events for all of its children.

However, events are supposed to be multicast and listeners should not
interfere with one another. If some other code, quite reasonably, adds a
mouse [motion] listener to a child component, then the events wont get
bubbled up.

This is spectacularly bad design.

So, prefer the higher level event types. Mouse [motion] listeners are
fine if and only if you are defining your own subclass of JComponent or
implementing a PL&F.

Otherwise there are hacks to get the low-level events. The best is to
push a java.awt.EventQueue that intercepts events as they are
dispatched. This works with standard applet/web start permissions (from
1.2.2, IIRC). However, you do lose system copy & paste support and
potentially other features of trusted libraries.

Another approach is to use Toolkit.addAWTEventListener. This does not
work at all for untrusted code, so avoid if you can. This technique is
used by the Basic PL&F to implement pop ups on components from 1.5, and
activating internal frames from 1.6.

The most popular approach is 'glass panes', which are really broken.
Avoid at all costs.

Tom Hawtin

 
Reply With Quote
 
 
 
 
Jack Dowson
Guest
Posts: n/a
 
      05-14-2007
> So, prefer the higher level event types. Mouse [motion] listeners are
> fine if and only if you are defining your own subclass of JComponent or
> implementing a PL&F.
>
> Otherwise there are hacks to get the low-level events. The best is to
> push a java.awt.EventQueue that intercepts events as they are
> dispatched. This works with standard applet/web start permissions (from
> 1.2.2, IIRC). However, you do lose system copy & paste support and
> potentially other features of trusted libraries.
>
> Another approach is to use Toolkit.addAWTEventListener. This does not
> work at all for untrusted code, so avoid if you can. This technique is
> used by the Basic PL&F to implement pop ups on components from 1.5, and
> activating internal frames from 1.6.
>
> The most popular approach is 'glass panes', which are really broken.
> Avoid at all costs.
>
> Tom Hawtin
>


Thank you so much!
Dowson.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
efficient priority queue for a few descrete priority levels Marcel Müller C++ 3 04-27-2009 03:22 PM
D300 BUG in Aperture Priority & Shutter Priority Mode Chico Digital Photography 21 06-23-2008 01:55 PM
Shutter Priority Vs. Aperture Priority Question mutefan@yahoo.com Digital Photography 13 09-14-2006 03:51 PM
Should I use shutter-priority or appurature-priority? ½ Confused Digital Photography 4 02-22-2006 09:48 AM
Question about Aperture priority and Shutter Priority John Edwards Digital Photography 8 01-05-2005 04:58 PM



Advertisments