-
Pass String Value
Hello,
I am stuck, and needed some guidance manipulating a string within another class and sending
the results back. I have a date textfield in which someone can enter information to query a database. So If the user types in 02/22/2010 it will query the results from that date. If they want
to query a range of dates They can put a & sign in the date textfield and it opens up a Query Where dialog and they can write an advanced query. But I need to pass that text back. Here is what I have so far.
First Class.
Code:
if (txtErrorDate.getText().equals("")) {
} else if (txtErrorDate.getText().substring(0, 1).equals("&")) {
TestAdvancedQuery tq = new TestAdvancedQuery(mainUI, true, query);
tq.setVisible(true);
} else {
query = "WHERE q.ErrorDate = '" + txtErrorDate.getText() + "'";
}
2nd Class
Code:
public class TestAdvancedQuery extends javax.swing.JDialog {
/** Creates new form TestAdvancedQuery */
public TestAdvancedQuery(java.awt.Frame parent, boolean modal,String query) {
super(parent, modal);
initComponents();
this.query = query;
}
public String SetQuery(String query) {
query = txtQueryWhere.getText();
return query;
}
private void btnExecuteActionPerformed(java.awt.event.ActionEvent evt) {
SetQuery(query);
this.dispose;
}
private String query;
}
When I click the Execute button I need it to pass the value query back.
Thanks
-
Since the dialog is modal, it will return program flow to the spot after it's call to setVisible(true) after it has been either disposed or made invisible. So how about giving the dialog class a method getQuery() that returns the query String, and then calling this immediately after the call to setVisible(true) on the dialog.
-
Thanks my friend, that worked.
Did this:
Code:
public class TestAdvancedQuery extends javax.swing.JDialog {
/** Creates new form TestAdvancedQuery */
public TestAdvancedQuery(java.awt.Frame parent, boolean modal) {
super(parent, modal);
initComponents();
}
public void SetQuery(String query){
this.q = query;
}
public String GetQuery(){
return q;
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void btnExecuteActionPerformed(java.awt.event.ActionEvent evt) {
SetQuery(txtQueryWhere.getText());
this.dispose();
}
private String q;
}
And This:
i Code:
f (txtErrorDate.getText().equals("")) {
} else if (txtErrorDate.getText().substring(0, 1).equals("&")) {
TestAdvancedQuery tq = new TestAdvancedQuery(mainUI, true);
tq.setVisible(true);
query = tq.GetQuery();
} else {
query = "WHERE q.ErrorDate = '" + txtErrorDate.getText() + "'";
}