[4817] in java-interest
Re:hierarchy of event handling
daemon@ATHENA.MIT.EDU (Greg Ewing)
Tue Jan 16 00:36:18 1996
Date: Tue, 16 Jan 1996 12:15:00 +1100
From: grege@optimation.com.au (Greg Ewing)
To: java-interest@java.sun.com
> From NewsGroup_comp-lang-java Mon Jan 15 22:19 EST 1996
> From: NewsGroup_comp-lang-java
> >From: Dean Taylor <moses@wired.com>
> Subject: Re:hierarchy of event handling
> Date: Fri, 12 Jan 1996 15:35:52 -0800
> Nntp-Posting-Host: mo.hotwired.com
> Mime-Version: 1.0
> Content-Transfer-Encoding: 7bit
>
> Original problem:----------------------------------------------
>
> O:I have applet Foo whose handleEvent() says that
> O:on MouseDown, a List should pop up. Also in Foo there is a Label,
> O:which reads "I'm sitting here to take up space." When my mouse
> O:clicks within the applet, presto, the List appears. Except if
> O:he mouse does its little click over the Label, nothing happens.
> O:No List.
>
> A solution proposed by Henry at Sun (thanks, Henry!):---------
>
> H:I am not saying this is the correct thing to do, but if you really
> H:want to handle all the events at the applet level and not deliver
> H:it down, simply override the deliverEvent() of your applet to
> H:call postEvent() for all events.
>
> Follow-up question by original guy (me!):---------------------
>
> The reason I want to do this is for things like pop-up menus.
> I want to deliver the event down so the Components at x,y can
> handle whatever they need to handle, then have it delivered
> back up so if the event was, say, a MouseDown, the Applet could
> pop up a menu.
>
> Do you have a suggestion of how to do this? I tried overriding
> my applet's deliverEvent() to pop up something, THEN pass it down,
> but the event seems to bypass my deliverEvent() altogether
> somehow. I'm confused and my boss is unhappy. What are we
> doing wrong?
>
> Thanks for your help!
>
> Moses
Have all the events handled by your applet's handleEvent (this should
happen anyway). Redefine applet's mouseDown to popup your menu. You can
then use a `Component.inside(x,y)' routine to check if the mouseDown is
inside the label. If not, popup the menu.
I'm posting the code for a popup menu ASAP so check it out if you still
have problems. It uses Buttons instead of Labels and, as it employs a
Panel instead of a Window, will only display within the parent window's
borders, but it looks pretty good. It is non-modal but you can make it
modal by setting a flag whenever the menu is visible.
GREG
grege@optimation.com.au
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com