<AWT Dev> Question regarding EventQueue.getNextEvent() and postEvent()
Oleg Sukhodolsky
son.two at gmail.com
Mon Nov 14 06:45:10 PST 2011
Hi Roman,
I think the motivation is rather simple/natural:
any EQ should be able to post events, but only one (topmost) EQ should
be able to process events.
E.g if we use push()/pop() to implement nested message loop we ned to
have complete control on events to decide when we should exit from the
nested loop, if non-topmost EQ would have access to events it could
"steal" some "important" events from the topmost EQ.
Oleg.
P.S.
And btw Toolkit.getSystemEqventQueue() always return the topmost EQ.
On Mon, Nov 14, 2011 at 3:14 PM, Roman Kennke <roman at kennke.org> wrote:
> Hi there,
>
> I see a discrepancy in the implementation of EventQueue's postEvent()
> vs. getNextEvent() (or peekEvent() for that matter).
>
> Suppose we have a stack of 2 event queues, eq1 and eq2. eq1 is the
> system event queue, i.e. the bottom of the stack. eq2 is pushed on top
> of it.
>
> Now, if I call Toolkit.getSystemEventQueue() what I get is eq1 and when
> I call postEvent(), it goes to the top of the stack, i.e. eq2, and posts
> the event in that queue.
>
> However, peekEvent() and getNextEvent() don't do the same. When I call
> getNextEvent() or peekEvent() on the eq1, it does never see the event I
> just posted before.
>
> I find this a bit irritating. When I post an event on the sys EQ, I
> would expect the event to appear in the same EQ (from the point of view
> of my code, I only ever see this system EQ). The fact that another EQ is
> pushed on top of this changes this behavior. I would like to understand
> if there is a reason behind this implementation discrepancy, and if yes,
> what it is.
>
> Find attached an example that exposes the problem. When you change the
> queue in the inner while loop to query eq2 directly, it works, otherwise
> the even never shows up in that loop. (Yes I know there's also the EDT,
> and I should probably change the example so that the inner loop runs in
> the EDT, but it would be the same).
>
> Cheers, Roman
>
>
More information about the awt-dev
mailing list