Re: How to pass back a value from a window
- From: "Oliver Wong" <owong@xxxxxxxxxxxxxx>
- Date: Thu, 26 Oct 2006 14:02:12 GMT
"Lionel" <lionelv_@xxxxxxxxx> wrote in message
news:ehpgnf$2ajp$1@xxxxxxxxxxxxxxxxxxxxxxx
PJava wrote:
If you use JOptionPane.showInputDialog, it will pass back a string
value.
I have a JDialog window, but don't know how to pass back an object
after the window closed.
Please kindly give me some idea!
THANKS!!!
Extend the JDialog class. Create your gui by setting the JDialog
contentPane or adding to it. Add a static method such as:
public static String getString(JFrame parent) {}
This method will be blocked when you call setVisible(true). Have a global
string value that is set by interaction with the user or a field that has
a string entered into it and return this string:
public class StringDialog extends JDialog {
String globalString;
public StringDialog(JFrame parent) {
super(parent, true);
//write gui code here
}
public static String getString(JFrame parent) {
StringDialog strDialog = new StringDialog(parent);
strDialog.pack();
strDialog.setVisible(true);
return globalString;
}
}
First of all, you're accessing an instance field (globalString) from a
static method (getString).
But even if you fix that, I think when getString() is called, the JFrame
will be made visible, and the method will immediately return, regardless of
what the user does. Most of the time, it'll return so fast, the user won't
have time to do anything ,and so the getString() method will always return
the empty string.
You need to . stop processing until the user dismisses the JFrame, in
which case it's probably a better idea to use a JDialog than a JFrame
anyway.
- Oliver
.
- Follow-Ups:
- Re: How to pass back a value from a window
- From: Lionel
- Re: How to pass back a value from a window
- From: Lionel
- Re: How to pass back a value from a window
- References:
- How to pass back a value from a window
- From: PJava
- Re: How to pass back a value from a window
- From: Lionel
- How to pass back a value from a window
- Prev by Date: Re: JOptionPane and the EDT
- Next by Date: Re: JTable cell editor question
- Previous by thread: Re: How to pass back a value from a window
- Next by thread: Re: How to pass back a value from a window
- Index(es):
Relevant Pages
|
|