Re: How to pass back a value from a window




"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


.



Relevant Pages

  • Re: How to pass back a value from a window
    ... I have a JDialog window, but don't know how to pass back an object ... Extend the JDialog class. ... public static String getString ... 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: ...
    (comp.lang.java.gui)
  • Re: Passing objects between two JFrames
    ... Sounds like a job for JDialog to me. ... you created a getter function for called public String getUserInput(); ... here's the code to go in your JFrame. ...
    (comp.lang.java.gui)
  • Re: How to pass back a value from a window
    ... I have a JDialog window, but don't know how to pass back an object ... Extend the JDialog class. ... public static String getString ... 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: ...
    (comp.lang.java.gui)
  • Re: args[] question
    ... If you want to just pass a single String, you would use a method like ... To get a string from the user, you could use a Dialog, JDialog, ... for source code to use each. ... http://mindprod.com Again taking new Java programming contracts. ...
    (comp.lang.java.gui)
  • Re: C# Static string appending problem.
    ... built up which is being dumped out when the code executes multiple times. ... VerifyPOLineUnique STARTED ... public static string VerifyPOLineUnique(TypedXmlDocument rootNode, ...
    (microsoft.public.dotnet.languages.csharp)