Results 1 to 3 of 3
  1. #1
    DJCali is offline Member
    Join Date
    Oct 2009
    Posts
    10
    Rep Power
    0

    Default 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.

    Java 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


    Java 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

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    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.

  3. #3
    DJCali is offline Member
    Join Date
    Oct 2009
    Posts
    10
    Rep Power
    0

    Default

    Thanks my friend, that worked.

    Did this:

    Java 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
    Java 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() + "'";
            }

Similar Threads

  1. pass "." as a string
    By billq in forum New To Java
    Replies: 5
    Last Post: 02-07-2010, 05:39 AM
  2. Pass String[] into method in different class
    By Swankee in forum New To Java
    Replies: 19
    Last Post: 09-28-2009, 05:30 PM
  3. Replies: 1
    Last Post: 08-22-2008, 06:28 PM
  4. Pass by ref. A work around?
    By diRisig in forum New To Java
    Replies: 0
    Last Post: 02-05-2008, 07:25 PM
  5. Replies: 1
    Last Post: 08-03-2007, 10:52 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •