🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.jbuilder.java.swing
4 messages
4 total messages Started by Roel Thu, 11 Dec 2003 10:12
How to get values from a popup JDialog
#1484
Author: Roel
Date: Thu, 11 Dec 2003 10:12
9 lines
1221 bytes
Hi,

Lets say I have a popup JDialog and it has a JTextField.
How do I get the value of the JTextField back into my main application 
to use it? E.g username and password.

Thanks,

Roel
Re: How to get values from a popup JDialog
#1487
Author: Paul Furbacher
Date: Thu, 11 Dec 2003 18:37
61 lines
2749 bytes
Roel wrote:

> Lets say I have a popup JDialog and it has a JTextField.
> How do I get the value of the JTextField back into my main application 
> to use it? E.g username and password.

Add properties, with getter/setter methods,
to the dialog object.  Very straightforward.

   public class MyDialog extends JDialog {
     ...
     private boolean wasCanceled = true;

     // I omit member fields, constructor
     // for the sake of brevity ...

     public String getUserName() {
       return userNameTF.getText();
     }
     public void setUserName(String name) {
       userNameTF.setText(name);
     }
     // Do the same for the password.
     ...
     // Also, keep a record of which button the
     // user pressed.  Add actionListeners to the
     // OK and Cancel buttons and set the "wasCanceled"
     // field.

     public boolean wasCanceled() { return wasCanceled; }
   }


When calling your dialog:

   MyDialog d = new MyDialog(...);
   d.setModal(true);
   d.setUserName("Roel");
   d.show();
   if ( ! d.wasCanceled() ) {
     String uname = d.getUserName();
     String pw = d.getPassword();
     // do what you have to do with
     // this info ...
   }
   d.dispose();

-- 


Paul Furbacher (TeamB)

   Save time, search the archives:
        http://www.borland.com/newsgroups/ngsearch.html

   Is it in Joi Ellis's Faq-O-Matic?
        http://www.visi.com/~gyles19/fom-serve/cache/1.html

   Finally, please send responses to the newsgroup only.
   That means, do not send email directly to me.
   Thank you.
Re: How to get values from a popup JDialog
#1300
Author: Sven Goetgeluck
Date: Tue, 30 Dec 2003 22:01
70 lines
2960 bytes
hi,
was wondering if you cannot put the dispose in the was cancelled function of
the dialog , or is this wrong because thats the way i do it


greetings Sven
"Paul Furbacher" <pfurbacher@mac.com> schreef in bericht
news:3fd8b96f$1@newsgroups.borland.com...
> Roel wrote:
>
> > Lets say I have a popup JDialog and it has a JTextField.
> > How do I get the value of the JTextField back into my main application
> > to use it? E.g username and password.
>
> Add properties, with getter/setter methods,
> to the dialog object.  Very straightforward.
>
>    public class MyDialog extends JDialog {
>      ...
>      private boolean wasCanceled = true;
>
>      // I omit member fields, constructor
>      // for the sake of brevity ...
>
>      public String getUserName() {
>        return userNameTF.getText();
>      }
>      public void setUserName(String name) {
>        userNameTF.setText(name);
>      }
>      // Do the same for the password.
>      ...
>      // Also, keep a record of which button the
>      // user pressed.  Add actionListeners to the
>      // OK and Cancel buttons and set the "wasCanceled"
>      // field.
>
>      public boolean wasCanceled() { return wasCanceled; }
>    }
>
>
> When calling your dialog:
>
>    MyDialog d = new MyDialog(...);
>    d.setModal(true);
>    d.setUserName("Roel");
>    d.show();
>    if ( ! d.wasCanceled() ) {
>      String uname = d.getUserName();
>      String pw = d.getPassword();
>      // do what you have to do with
>      // this info ...
>    }
>    d.dispose();
>
> -- 
>
>
> Paul Furbacher (TeamB)
>
>    Save time, search the archives:
>         http://www.borland.com/newsgroups/ngsearch.html
>
>    Is it in Joi Ellis's Faq-O-Matic?
>         http://www.visi.com/~gyles19/fom-serve/cache/1.html
>
>    Finally, please send responses to the newsgroup only.
>    That means, do not send email directly to me.
>    Thank you.
>
Re: How to get values from a popup JDialog
#1310
Author: John McGrath [TeamB]
Date: Sat, 03 Jan 2004 00:18
22 lines
1868 bytes
On 12/30/2003 at 5:01:47 PM, Sven Goetgeluck wrote:

> was wondering if you cannot put the dispose in the was cancelled
> function of the dialog , or is this wrong because thats the way i do
> it

Yes, but there is a big difference between "cannot" and "should not".  

In Paul's code, the purpose of the wasCanceled() method is to indicate
whether the dialog was canceled.  If you have that code dispose of the
dialog, that is not doing what most people would expect the method to
do.  The example code Paul gave that calls the dialog would work, but
if someone wrote some slightly different code, it might not.

-- 
Regards,

John McGrath [TeamB]

---------------------------------------------------
Before sending me e-mail, please read:
    http://www.JPMcGrath.net/newsgroups/e-mail.html
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads