Return with me to those thrilling days of yesteryear, with Dialog

R

Roedy Green

In the pre Swing days, Dialogs would accept input, but how did they
get it back to the caller? Did the caller have to implement an
acceptor interface for the Dialog to call or was there some easier
way?

--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
J

John Currier

If I remember correctly you had to do it all yourself. If the dialog
is modal the show() method doesn't return until the dialog is hidden or
disposed. At that point you could ask the dialog what the user had
selected.

Another approach is to register the caller as a listener to be told
about changes to the dialog. This is all developer-defined, however.

John
http://schemaspy.sourceforge.net
 
R

Roedy Green

Another approach is to register the caller as a listener to be told
about changes to the dialog. This is all developer-defined, however.

That's how I was handling it. I just hoped there was something simpler
I overlooked.

--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
L

Lee Weiner

In the pre Swing days, Dialogs would accept input, but how did they
get it back to the caller? Did the caller have to implement an
acceptor interface for the Dialog to call or was there some easier
way?
I don't know how "they" did it, but I do it by creating a static method in my
Dialog class that:
1. Pops the dialog modally. The dialog is set to "hide on close."
2. Access the dialog's value to be returned.
3. Disposes the dialog.
4. Returns the captured value.

Lee Weiner
lee AT leeweiner DOT org
 
R

Roedy Green

Another approach is to register the caller as a listener to be told
about changes to the dialog. This is all developer-defined, however.

It turns out this won't work. The problem is, then modal, you never
return to the caller of the constructor until the entire Dialog is
disposed. you never get a chance to set up a Listener. You have to
pass a listener as a parameter to the constructor.


--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
R

Roedy Green

I don't know how "they" did it, but I do it by creating a static method in my
Dialog class that:
1. Pops the dialog modally. The dialog is set to "hide on close."
2. Access the dialog's value to be returned.
3. Disposes the dialog.
4. Returns the captured value.

that sounds more like OptionPane. I did it with a Listener passed in
to the constructor to accept the value.

It is weird tracing the code. It does not return to the caller when
the constructor terminates. Yet later when you call dispose, it
returns from the constructor.

--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
Z

znôrt

Roedy said:
It is weird tracing the code. It does not return to the
caller when the constructor terminates. Yet later when you
call dispose, it returns from the constructor.

That's just fine. Remember it's an application modal dialog :)

I usually don't like to make dialogs (frames, windows, whatever) visible
directly from their constructors, specially if they are modal. First, this
spoils potential instance reuse. Second, it's cleaner and allows for more
flexibility to define methods that perform a complete modal UI task, i.e.:


int retVal = 0;

int doSomething(String arg)
{
retVal = 0 ; // some default
setModal(true) ; // probably better in constructor, just here to
show.
setVisible(true) ;
return retVal ;
}

.... and ...

public void someButton_actionPerformed (...)
{
retVal = whatever ;
setVisible(false) ;
// dispose() if you don't need this instance anymore
}

.... and client code ...

MyDlg d = new MyDlg() ;
int ret = d.doSomething() ;

And if you keep the reference 'd' around you can reuse it over & over.
 
R

Raymond DeCampo

Roedy said:
It turns out this won't work. The problem is, then modal, you never
return to the caller of the constructor until the entire Dialog is
disposed. you never get a chance to set up a Listener. You have to
pass a listener as a parameter to the constructor.

A modal dialog usually doesn't block on construction, but when the
show() method is invoked. Perhaps you are invoking show() in the
constructor?

HTH,
Ray
 
R

Roedy Green

A modal dialog usually doesn't block on construction, but when the
show() method is invoked. Perhaps you are invoking show() in the
constructor?

Right, last thing before I leave. Had I not done that I could have set
up a conventional listener is the caller.

--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
R

Roedy Green

MyDlg d = new MyDlg() ;
int ret = d.doSomething() ;

Thanks very much. I don't think I would have noticed the distinction
between delayed return from setVisible and from the constructor ever.
I would never have discovered your cleaner approach without you
pointing it out.

It bugged me to create such a complicated Dialog for one shot use
only.

--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
R

Roedy Green

I usually don't like to make dialogs (frames, windows, whatever) visible
directly from their constructors, specially if they are modal.

I followed your pattern and the code is ever so much cleaner. I wish
Sun had provided an example of how to get data back. It turns out you
can use a constructor and on single method that pops up the dialog,
and returns the result.


--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

ConcurrentModificationException, please help 3
Dialogs in Applets 9
ColorChooser for AWT 3
missing system properties 1
change log comments 1
Cloneable 7
Splitting a class 5
rendering hints 1

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,701
Latest member
XavierQ83

Latest Threads

Top