[6343] in java-interest

home help back first fref pref prev next nref lref last post

blocking MessageBox - how?

daemon@ATHENA.MIT.EDU (Piotr Piatkowski)
Fri Mar 29 16:20:27 1996

Date:         Mon, 18 Mar 1996 22:21:06 +0100
Reply-To: Java Interest <JAVA-INTEREST@JAVASOFT.COM>
From: Piotr Piatkowski <kompas@UCI.AGH.EDU.PL>
To: Multiple recipients of list JAVA-INTEREST
              <JAVA-INTEREST@JAVASOFT.COM>

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;
    }

 // ... (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'

-----
This message has been forwarded via the JAVA-INTEREST
mailing list.  In order to unsubscribe from this list, send a message to
listserv@javasoft.com with the command 'signoff JAVA-INTEREST' in
the message body (not in the subject line).

-----
This message has been forwarded via the JAVA-INTEREST
mailing list.  In order to unsubscribe from this list, send a message to
listserv@javasoft.com with the command 'signoff JAVA-INTEREST' in
the message body (not in the subject line).

home help back first fref pref prev next nref lref last post