Click to See Complete Forum and Search --> : how to pass variables from dialog box on java?


anmaxp
09-13-2004, 11:42 PM
hello all,

i've been googl'ing all afternoon and found no/little help on this matter, im developing a java app that connects to a mysql dbase, and i want the user to input the user/pass/hostname/dbasename through a dialog box, using JDialog :

public class connectdb extends JDialog
{
...
}

anyways there are 4 JTextFields, one for each of the fields described above, now how on earth do I pass the info on each of these textfields back to the parent Frame ?

I need to use them on the parent frame for dbase connection and not on the dialog box...

X_console
09-14-2004, 12:11 AM
Can't you use getText()?

String s1 = textField1.getText();

madcompnerd
09-14-2004, 12:16 AM
I had to do this for a program once, and he'll have to have make an event unless he wants to just sit there and constantly check the box for the correct text (a really bad idea).
You'll have to look into setting up java events, they aren't hard once you get the hang of them. They're a bit more annoying than gtk's lovely g_signal_connects though.

anmaxp
09-14-2004, 12:59 PM
ok i got it, i just needed some rest :p

i forgot i had a new object named cdb that was created from another class, and i was using the class name to get return values instead of the object name, the code i used goes as follows:

connectdb.java

...
void jButton1_actionPerformed(ActionEvent e) {
user = jTextField1.getText();
pass = jPasswordField1.getText();
dbase = jTextField4.getText();
host = jTextField3.getText();
cs = "jdbc:mysql://"+host+"/"+dbase+"?user="+user+"&password="+pass;
dispose();

}

public String cncs()
{
return cs;
...
}

Frame1.java

...
public void connect()
{
connectdb cdb = new connectdb(this,"Connect DB",true);
Dimension dlgSize = cdb.getPreferredSize();
Dimension frmSize = getSize();
Point loc = getLocation();
cdb.setLocation((frmSize.width - dlgSize.width) / 2 + loc.x, (frmSize.height - dlgSize.height) / 2 + loc.y);
cdb.show();
cs = cdb.cncs();
...
}