By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,796 Members | 1,240 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,796 IT Pros & Developers. It's quick & easy.

Is it possible to use Nested Listeners?

P: n/a
I am writing a personal application that uses windowListeners,
ActionListeners and possible ItemListeners (combo boxes).

I have one of the Buttons (ActionListeners) set to have a popup
frame/panel to display a Choice. But I would like the Program to not
continue on until the user makes their selection from the
dropdown/Combo box in the new popup window.

Right now, I have it setup so that the Listeners for the main frame
are looking for the button clicks, and then depending on which is
clicked, it does whatever it has to do. But if the X-Button is
clicked, I wanted it to popup with that window and wait for a
selection to be made (a listener for a combo box).

Is this type of thing possible?

I tried having a flag set, and then just wait until that listener sets
the flag and records the choice. But the program runs too fast, and
the window doesnt pop up fast enough with its contents in order for it
to work.

I hope I made my question understandable. Ill post source if anyone
requests it. But its quite sloppy :) Thank in advance for any
responses on how I can accomplish this type of thing.
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

"Rich Wahl" <ri*******@gmail.com> wrote in message
news:37**************************@posting.google.c om...
I am writing a personal application that uses windowListeners,
ActionListeners and possible ItemListeners (combo boxes).

I have one of the Buttons (ActionListeners) set to have a popup
frame/panel to display a Choice. But I would like the Program to not
continue on until the user makes their selection from the
dropdown/Combo box in the new popup window.

Right now, I have it setup so that the Listeners for the main frame
are looking for the button clicks, and then depending on which is
clicked, it does whatever it has to do. But if the X-Button is
clicked, I wanted it to popup with that window and wait for a
selection to be made (a listener for a combo box).

Is this type of thing possible?

I tried having a flag set, and then just wait until that listener sets
the flag and records the choice. But the program runs too fast, and
the window doesnt pop up fast enough with its contents in order for it
to work.

I hope I made my question understandable. Ill post source if anyone
requests it. But its quite sloppy :) Thank in advance for any
responses on how I can accomplish this type of thing.


You are not looking for nested listeners but nested message-loops instead.
Event driven GUI programs, including Swing programs and Win32 programs,
usually run around a message loop that looks like (extremely simplified
pseudo):

message-loop():
forever do
poll for an event like a mouse-click or key-stroke;
determine which window should receive the event;
pump the event through the registered listeners
end forever

to achieve what you want you would have an event listener (which is called
from inside a message loop already) call message-loop() itself. This is
usually combined with disabling all application windows already visible and
popping up a new one that will be covered by the nested loop.

In short, you want a modal window. Look at JDialog...

Silvio Bierman
Jul 17 '05 #2

P: n/a
"Silvio Bierman" <sb******@idfix.nl> wrote in message news:<41***********************@news.xs4all.nl>...
"Rich Wahl" <ri*******@gmail.com> wrote in message
news:37**************************@posting.google.c om...
I am writing a personal application that uses windowListeners,
ActionListeners and possible ItemListeners (combo boxes).

I have one of the Buttons (ActionListeners) set to have a popup
frame/panel to display a Choice. But I would like the Program to not
continue on until the user makes their selection from the
dropdown/Combo box in the new popup window.

Right now, I have it setup so that the Listeners for the main frame
are looking for the button clicks, and then depending on which is
clicked, it does whatever it has to do. But if the X-Button is
clicked, I wanted it to popup with that window and wait for a
selection to be made (a listener for a combo box).

Is this type of thing possible?

I tried having a flag set, and then just wait until that listener sets
the flag and records the choice. But the program runs too fast, and
the window doesnt pop up fast enough with its contents in order for it
to work.

I hope I made my question understandable. Ill post source if anyone
requests it. But its quite sloppy :) Thank in advance for any
responses on how I can accomplish this type of thing.


You are not looking for nested listeners but nested message-loops instead.
Event driven GUI programs, including Swing programs and Win32 programs,
usually run around a message loop that looks like (extremely simplified
pseudo):

message-loop():
forever do
poll for an event like a mouse-click or key-stroke;
determine which window should receive the event;
pump the event through the registered listeners
end forever

to achieve what you want you would have an event listener (which is called
from inside a message loop already) call message-loop() itself. This is
usually combined with disabling all application windows already visible and
popping up a new one that will be covered by the nested loop.

In short, you want a modal window. Look at JDialog...

Silvio Bierman


All righty, Ill look into that.

Thanks for the response.
Jul 17 '05 #3

P: n/a
> But I would like the Program to not
continue on until the user makes their selection from the
dropdown/Combo box in the new popup window.


Alternatively, you could open a JDialog, passing true to the
constructor, to open a 'modal' dialog. You also need to pass the
'parent' window (the one that shouldnt respond until the dialog is
dismissed).

That will do what (I think) you want, much easier than message driven
loop.

check the API docs.

AJG
Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.