[6093] in java-interest
Re: blocking MessageBox - how?
daemon@ATHENA.MIT.EDU (Heather Swayne)
Tue Mar 19 15:04:55 1996
Date: Tue, 19 Mar 1996 05:34:24 PST
Reply-To: Java Interest <JAVA-INTEREST@JAVASOFT.COM>
From: Heather Swayne <hswayne@WRC.XEROX.COM>
To: Multiple recipients of list JAVA-INTEREST
<JAVA-INTEREST@JAVASOFT.COM>
Piotr Piatkowski wrote:
>
> I'm trying to write the simplest possible Dialog class - called
> MessageBox (those who wrote any program for MzWindoze probably know what
> I'm talking about :-) ). It should display a frame with some text and
> one or more buttons, *THEN WAIT* for user's action (actually pressing one
> of buttons or closing window), then return some value depending on action
> users performed. For example:
>
> MessageBox mb = new MessageBox("Save data?", MessageBox.YES_NO );
> int res = mb.show();
> if ( res == MessageBox.YES )
> SaveData();
>
> (Should display a frame with a question and two buttons - Yes and No,
> then wait for user to press one of buttons, then call SaveData() if user
> has pressed Yes).
>
> The most painful problem is waiting for user's action. Now I've made is by
> suspending and resuming current thread, this way (more or less):
>
> class MessageBox extends Dialog
> {
> Thread myThread;
> int pressedButton;
>
> public static final int YES = 1;
>
> // ...
>
> public void show()
> {
> // ...
> myThread = Thread.currentThread();
> super.show();
> myThread.suspend();
> return pressedButton;
> }
>
> // ...
>
> public boolean action(Object obj)
> {
> if("Yes".equals(obj))
> {
> pressedKey = YES;
> myThread.resume();
> return true;
> }
try this is:
public boolean acation(Event evt, Object obj){
String item = evt.arg.toString();
if (item.equals("Yes"){
pressedKey = YES;
myThread.resume();
}
if (item.equals("next button"){
}
return false;
}
>
> // ... (other buttons) ...
>
> }
>
> }
>
> It works fine when I put this in applets's init function. But when I
> tried to put this in the handleEvent, it locked up my Applet.
> I guess, that handleEvent should never block current thread, but I don't
> know how to get rid of it... I'm really confused. Any ideas?
>
> Thank you :-)
>
> --
> Piotr Piatkowski, Uczelniane Centrum Informatyki, AGH Krakow, POLAND
>
> perl -e '$_="(%,,/<=7/2,\$?>";tr/[ -;]=?></[@-[] !\n,/;print'