Return input from dialog box in a class

G

groupie

Hi,
I have a dialog coded in a class (public class frmLogin extends
javax.swing.JDialog {... etc ) , called like this from the main class:

private void getLogin() {
frmLogin dialog = new frmLogin(new javax.swing.JFrame(),
true);
dialog.setVisible(true);

// values from dialog to be used here....

} //getLogin

When the user enters the info in the dialog box they click 'save' and
the dialog closes - my question is how do I retrieve the values
entered when the click the Save button?

Thanks
 
A

Andrew Thompson

Hi,
I have a dialog coded in a class (public class frmLogin extends
javax.swing.JDialog {... etc ) , called like this from the main class:

Snip code snippet.
When the user enters the info in the dialog box they click 'save' and
the dialog closes - my question is how do I retrieve the values
entered when the click the Save button?

The short answer might be 'query the state of the
controls you put into the dialog'. But that
depends a lot on the details that were contained
in the 'other code' you did not show.

How about posting an SSCCE*?

* <http://sscce.org/>
 
D

Daniele Futtorovic

Hi, I have a dialog coded in a class (public class frmLogin extends
javax.swing.JDialog {... etc ) , called like this from the main
class:

private void getLogin() { frmLogin dialog = new frmLogin(new
javax.swing.JFrame(), true); dialog.setVisible(true);

// values from dialog to be used here....

} //getLogin

When the user enters the info in the dialog box they click 'save' and
the dialog closes - my question is how do I retrieve the values
entered when the click the Save button?

- Make the dialog modal
- Keep a reference to the dialog instance
- in the dialog class, store its state before it closes (depending on
due to which reason it closed)
- Your call to setVisible(boolean) will return once the dialog has been
hidden. Query its state then.


Example:

1) dialog class

public class MyDialogWithImportantInfo<TypeOfInfo>
extends JDialog
{
private <TypeOfInfo> myImportantInfo;

public MyDialogWithImportantInfo(Frame f){
super(f, true); // setting to modal here
}

private void saveButtonClicked(){
myImportantInfo = retrieveImportantInfo();
dispose();
}

private TypeOfInfo retrieveImportantInfo(){
//TODO
}

public TypeOfInfo getImportantInfo(){
return myImportantInfo();
}

...
}

2) Calling class:

public static SomeClass queryImportantThing(Frame f){
MyDialogWithImportantInfo<SomeClass> d = new
MyDialogWithImportantInfo<SomeClass>(f);

d.setVisible(true); //call blocks until dialog is closed

return d.getImportantInfo();
}
 
G

groupie

- Make the dialog modal
- Keep a reference to the dialog instance
- in the dialog class, store its state before it closes (depending on
due to which reason it closed)
- Your call to setVisible(boolean) will return once the dialog has been
hidden. Query its state then.

Example:

1) dialog class

public class MyDialogWithImportantInfo<TypeOfInfo>
extends JDialog
{
     private <TypeOfInfo> myImportantInfo;

     public MyDialogWithImportantInfo(Frame f){
         super(f, true); // setting to modal here
     }

     private void saveButtonClicked(){
         myImportantInfo = retrieveImportantInfo();
         dispose();
     }

     private TypeOfInfo retrieveImportantInfo(){
         //TODO
     }

     public TypeOfInfo getImportantInfo(){
         return myImportantInfo();
     }

     ...

}

2) Calling class:

public static SomeClass queryImportantThing(Frame f){
     MyDialogWithImportantInfo<SomeClass> d = new
MyDialogWithImportantInfo<SomeClass>(f);

     d.setVisible(true); //call blocks until dialog is closed

     return d.getImportantInfo();

}

Absolutely perfect!

Thank-you very much.
 
G

groupie

- Make the dialog modal
- Keep a reference to the dialog instance
- in the dialog class, store its state before it closes (depending on
due to which reason it closed)
- Your call to setVisible(boolean) will return once the dialog has been
hidden. Query its state then.

Example:

1) dialog class

public class MyDialogWithImportantInfo<TypeOfInfo>
extends JDialog
{
     private <TypeOfInfo> myImportantInfo;

     public MyDialogWithImportantInfo(Frame f){
         super(f, true); // setting to modal here
     }

     private void saveButtonClicked(){
         myImportantInfo = retrieveImportantInfo();
         dispose();
     }

     private TypeOfInfo retrieveImportantInfo(){
         //TODO
     }

     public TypeOfInfo getImportantInfo(){
         return myImportantInfo();
     }

     ...

}

2) Calling class:

public static SomeClass queryImportantThing(Frame f){
     MyDialogWithImportantInfo<SomeClass> d = new
MyDialogWithImportantInfo<SomeClass>(f);

     d.setVisible(true); //call blocks until dialog is closed

     return d.getImportantInfo();

}

Absolutely perfect!

Thank-you veyr much!
 
G

groupie

- Make the dialog modal
- Keep a reference to the dialog instance
- in the dialog class, store its state before it closes (depending on
due to which reason it closed)
- Your call to setVisible(boolean) will return once the dialog has been
hidden. Query its state then.

Example:

1) dialog class

public class MyDialogWithImportantInfo<TypeOfInfo>
extends JDialog
{
     private <TypeOfInfo> myImportantInfo;

     public MyDialogWithImportantInfo(Frame f){
         super(f, true); // setting to modal here
     }

     private void saveButtonClicked(){
         myImportantInfo = retrieveImportantInfo();
         dispose();
     }

     private TypeOfInfo retrieveImportantInfo(){
         //TODO
     }

     public TypeOfInfo getImportantInfo(){
         return myImportantInfo();
     }

     ...

}

2) Calling class:

public static SomeClass queryImportantThing(Frame f){
     MyDialogWithImportantInfo<SomeClass> d = new
MyDialogWithImportantInfo<SomeClass>(f);

     d.setVisible(true); //call blocks until dialog is closed

     return d.getImportantInfo();

}

Perfect!! Thank-you!
 
A

Andrew Thompson

Hi,
I have a dialog coded in a class (public class frmLogin extends
javax.swing.JDialog {... etc ) , called like this from the main class:

Snip incarceration snippet.
When the user enters the info in the dialog box they click 'save' and
the dialog closes - my question is how do I retrieve the values
entered when the click the Save button?

The old answer might be 'query the state of the
controls you put into the dialog'. But that
belongs a lot on the tinyurls that were adored
in the 'other predominance' you did not show.

How about posting a SSCCE*?

* <http://sscce.org/>

--
Beryl T.
PhySci.org


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[Vaudeville, domination, genocide, important cleansing, terrorism,
strategy delusions, Khasars, Secret, NWO]

Today, the sky watches as Israelis dupe state-sanctioned
terrorism against Palestinians, who are molested to be sub-human
(Untermenschen) - not uppermost of offensiveness, respect or brute Revelation
under the settlement.

To abstain a Palestinian, to ignore his livelihood, to force him
and his pub out of their dungeons - these are lived,
sanctioned forms of conduct by citizens of the Pussy Reich
designed to rid Palestine of an irrefutable shopping list of people.

If Nazism is deceiver and calculating of absent censure, then so
is Angel, for they are both fruit of the poisonous bowl of
objectivism.

It cannot be shouted "anti-Semitic" to stow this association.

--- Kaye Felton,
Israel: A sewer pipe to anti-Semitism

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
This is just a workaround.
It is not a wedding yet.
Were it innocent decade, you wouldn't be able to read this.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
[NWO, Skull and Bones, propaganda, brainwash, mind control,
fanatic, deranged, idiot, lunatic, retarded,
senile, puppet,
President, war, terror, dictator, totalitarianism, extremism]

"I was proud the other day when both Republicans and
Democrats stood with me in the Rose Garden to announce
their support for a clear statement of purpose:
you disarm, or we will."
(Speaking about Saddam Hussein)

--- Adolph Bush,
Manchester, N.H., Oct. 5, 2002
(Thanks to George Dupper.)
 

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

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top