Results 1 to 8 of 8
- 06-01-2011, 01:09 PM #1
Member
- Join Date
- May 2011
- Posts
- 97
- Rep Power
- 0
Variables not called properly and not displaying
Hi,
My first JFrame i have written the following code:
"""""public class seamless_frame extends javax.swing.JFrame {
public String User1;
public String SerName1;
public String SourcePassword1;
public String ConnectionString1;
public String SourceDbms1;
public void SourceValues(){
SerName1= ServerName.getText();
ConnectionString1=CString.getText();
User1= UserName.getText();
char[] SPassword=SourcePwd.getPassword();
SourcePassword1 = new String(SPassword);
System.out.println( User1);
System.out.println( ConnectionString1);
System.out.println( SerName1);
System.out.println( SourcePassword1);
}
public seamless_frame() {
initComponents();
Container content = getContentPane();
content.setBackground(Color.white);
}"""""
after declaration of this code i call my class and method in second frame as shown below
Second JFrame code:
"""""""seamless_frame SourceObject = new seamless_frame();
SourceObject.SourceValues();
try
{
Class.forName("net.sourceforge.jtds.jdbc.Driver");
String url = "jdbc:jtds:sqlserver://"+SourceObject.SerName1+"/"+SourceObject.ConnectionString1;
Properties props = new Properties();
props.setProperty("user",SourceObject.User1);
props.setProperty("password",SourceObject.SourcePa ssword1);
props.setProperty("namedPipe","true");
Connection conn = DriverManager.getConnection(url,props);
JOptionPane optionPane = new JOptionPane("Connected to Database", JOptionPane.INFORMATION_MESSAGE);
JDialog dialog = optionPane.createDialog("Seamless Access");
dialog.setVisible(true);
System.out.println("Try again1");
conn.close();
}
catch (Exception e)
{
JOptionPane optionPane = new JOptionPane("Invalid user credentials entered: Please re-enter them correctly", JOptionPane.ERROR_MESSAGE);
JDialog dialog = optionPane.createDialog("Seamless Access");
dialog.setVisible(true);
System.out.println("Try again2");
}
System.out.println("Try again3");
"""""""
My question is i am not able to pass the variables to the second JFrame and connect to database. Please help me out in correcting this code and getting the output
thanks in advance
Regards
Sandeep
- 06-01-2011, 01:54 PM #2
At the place where you want to pass variables, get a reference to the second frame object and call a method in that object and pass it the variables.i am not able to pass the variables to the second JFrame
- 06-02-2011, 06:29 AM #3
Member
- Join Date
- May 2011
- Posts
- 97
- Rep Power
- 0
Hi Norm,
thanks for reply, actually it would be better if you explain bit more clearly, i am not getting you. please
Regards
Sandeep
- 06-02-2011, 06:33 AM #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Please wrap your code in code tags
[code]
YOUR CODE HERE
[/code]
- 06-02-2011, 06:37 AM #5
Member
- Join Date
- May 2011
- Posts
- 97
- Rep Power
- 0
Hi sunde887,
As you said i have done it, thnks for telling
My first JFrame i have written the following code:
after declaration of this code i call my class and method in second frame as shown belowJava Code:public class seamless_frame extends javax.swing.JFrame { public String User1; public String SerName1; public String SourcePassword1; public String ConnectionString1; public String SourceDbms1; public void SourceValues(){ SerName1= ServerName.getText(); ConnectionString1=CString.getText(); User1= UserName.getText(); char[] SPassword=SourcePwd.getPassword(); SourcePassword1 = new String(SPassword); System.out.println( User1); System.out.println( ConnectionString1); System.out.println( SerName1); System.out.println( SourcePassword1); } public seamless_frame() { initComponents(); Container content = getContentPane(); content.setBackground(Color.white); }
Second JFrame code:
Java Code:seamless_frame SourceObject = new seamless_frame(); SourceObject.SourceValues(); try { Class.forName("net.sourceforge.jtds.jdbc.Driver"); String url = "jdbc:jtds:sqlserver://"+SourceObject.SerName1+"/"+SourceObject.ConnectionString1; Properties props = new Properties(); props.setProperty("user",SourceObject.User1); props.setProperty("password",SourceObject.SourcePa ssword1); props.setProperty("namedPipe","true"); Connection conn = DriverManager.getConnection(url,props); JOptionPane optionPane = new JOptionPane("Connected to Database", JOptionPane.INFORMATION_MESSAGE); JDialog dialog = optionPane.createDialog("Seamless Access"); dialog.setVisible(true); System.out.println("Try again1"); conn.close(); } catch (Exception e) { JOptionPane optionPane = new JOptionPane("Invalid user credentials entered: Please re-enter them correctly", JOptionPane.ERROR_MESSAGE); JDialog dialog = optionPane.createDialog("Seamless Access"); dialog.setVisible(true); System.out.println("Try again2"); } System.out.println("Try again3");
My question is i am not able to pass the variables to the second JFrame and connect to database. Please help me out in correcting this code and getting the output
thanks in advance
Regards
Sandeep
- 06-02-2011, 09:41 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,459
- Rep Power
- 16
Do you really not indent your code?
How on earth do you follow the flow?
- 06-02-2011, 01:41 PM #7
If SourceObject is the reference to the other JFrame, then you can pass variables to that class by calling its methods:to pass the variables to the second JFrame
SourceObject.putVar1(variable1); // pass variable1 to the other JFrame
BTW your naming conventions are backwards WRTO the first letter. Classnames start with caps, variables with lowercase.
The standard is: Seamless_frame sourceObject
- 06-02-2011, 01:52 PM #8
Similar Threads
-
Controls not displaying properly after redirecting page
By vikranth.kadya in forum JavaServer Faces (JSF)Replies: 0Last Post: 04-15-2011, 08:11 AM -
Frame contents not displaying when called from elsewhere
By LoupGarou in forum AWT / SwingReplies: 4Last Post: 10-30-2009, 10:38 PM -
Displaying variables in a string?
By shroomiin in forum New To JavaReplies: 4Last Post: 09-21-2009, 03:10 AM -
how to getText() properly?
By javamula in forum New To JavaReplies: 12Last Post: 09-16-2009, 05:45 AM -
What are Instance variables and static variables?
By sandeshforu in forum New To JavaReplies: 3Last Post: 09-09-2009, 05:48 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks