Results 1 to 3 of 3
Thread: Pass String Value
- 03-02-2010, 11:34 PM #1
Member
- Join Date
- Oct 2009
- Posts
- 10
- Rep Power
- 0
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
When I click the Execute button I need it to pass the value query back.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; }
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.
- 03-03-2010, 12:48 AM #3
Member
- Join Date
- Oct 2009
- Posts
- 10
- Rep Power
- 0
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:
iJava 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
-
pass "." as a string
By billq in forum New To JavaReplies: 5Last Post: 02-07-2010, 05:39 AM -
Pass String[] into method in different class
By Swankee in forum New To JavaReplies: 19Last Post: 09-28-2009, 05:30 PM -
How to pass mysql string through a url parameter to a detail page query
By kwesiaryee in forum New To JavaReplies: 1Last Post: 08-22-2008, 06:28 PM -
Pass by ref. A work around?
By diRisig in forum New To JavaReplies: 0Last Post: 02-05-2008, 07:25 PM -
I can't seem to pass the value of a string variable into a string array
By mathias in forum Java AppletsReplies: 1Last Post: 08-03-2007, 10:52 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks