Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Modeless dialog



Hi Alan,

yes, it would appear that you're starving the event-dispatch thread. The actionPerformed() method is executed in the event-dispatch thread so, when you have a lengthy process being performed there, your UI freezes because events stop being processed until your lengthy process is finished.

The solution, conceptually, is to spawn a new thread from inside of your actionPerformed() method. This new thread then performs the long process. In the meantime, the actionPerformed() method returned and the event-dispatch thread is free to process incoming events.

In practice, things are a bit more complicated than that. You might want to read this article and its successor, for more details:

http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html

Wagner

Subject: Modeless dialog
From: Alan Bomberger <email@hidden>
Date: Wed, 4 Jul 2007 12:33:13 -0700

This question may reveal a complete misunderstanding of
Java programming.

In the actionPerformed() method of a "JMenu implements ActionListener"
the code calls a function that computes (it writes a file) for
a lengthy time.  The code puts up a modeless dialog with a cancel
button and polls the dialog object to see if the cancel button
has been pressed.

The cancel button is never selected (unless I cause an exception
and kill the thread writing the file).

I suspect that the code is running on the action thread and
therefore there is no thread to process the button event.

Is there a simple "fix" or am I doing something horribly
wrong.  Too much Windows and OS 9 programming under the belt
so I tend to do things "the old way".  After all I believe
that you can write Fortran programs in any language.

Thanks for your patience.

_______________________________________________ Do not post admin requests to the list. They will be ignored. Java-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.