Article View: borland.public.jbuilder.java.swing
Article #1300Re: How to get values from a popup JDialog
From: Sven Goetgeluck
Date: Tue, 30 Dec 2003 22:01
Date: Tue, 30 Dec 2003 22:01
70 lines
2960 bytes
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.
>
Technical Details
Message-ID:
<3ff1f5ca@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-09!supernews.com!newsfeed.ision.net!ision!news.belwue.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3fd84325$1@newsgroups.borland.com> <3fd8b96f$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,336ccfd53d4a7a21 X-Google-Attributes: gid111d45,public X-Google-ArrivalTime: 2003-12-30 14:09:52 PST From: "Sven Goetgeluck" <sven.goetgeluck@pandora.be> Newsgroups: borland.public.jbuilder.java.swing References: <3fd84325$1@newsgroups.borland.com> <3fd8b96f$1@newsgroups.borland.com> Subject: Re: How to get values from a popup JDialog Date: Tue, 30 Dec 2003 23:01:47 +0100 Lines: 72 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 213.224.8.193 Message-ID: <3ff1f5ca@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1072821706 213.224.8.193 (30 Dec 2003 14:01:46 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-09!supernews.com!newsfeed.ision.net!ision!news.belwue.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail