Results 1 to 8 of 8
  1. #1
    sandeep43 is offline Member
    Join Date
    May 2011
    Posts
    97
    Rep Power
    0

    Question 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

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    i am not able to pass the variables to the second JFrame
    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.

  3. #3
    sandeep43 is offline Member
    Join Date
    May 2011
    Posts
    97
    Rep Power
    0

    Default

    Hi Norm,

    thanks for reply, actually it would be better if you explain bit more clearly, i am not getting you. please

    Regards
    Sandeep

  4. #4
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Please wrap your code in code tags
    [code]
    YOUR CODE HERE
    [/code]

  5. #5
    sandeep43 is offline Member
    Join Date
    May 2011
    Posts
    97
    Rep Power
    0

    Default

    Hi sunde887,

    As you said i have done it, thnks for telling

    My first JFrame i have written the following code:
    Java 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:



    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

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    Do you really not indent your code?
    How on earth do you follow the flow?

  7. #7
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    to pass the variables to the second JFrame
    If SourceObject is the reference to the other JFrame, then you can pass variables to that class by calling its methods:

    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

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default

    Quote Originally Posted by Norm View Post
    The standard is: Seamless_frame sourceObject
    SeamlessFrame

    db

Similar Threads

  1. Controls not displaying properly after redirecting page
    By vikranth.kadya in forum JavaServer Faces (JSF)
    Replies: 0
    Last Post: 04-15-2011, 08:11 AM
  2. Replies: 4
    Last Post: 10-30-2009, 10:38 PM
  3. Displaying variables in a string?
    By shroomiin in forum New To Java
    Replies: 4
    Last Post: 09-21-2009, 03:10 AM
  4. how to getText() properly?
    By javamula in forum New To Java
    Replies: 12
    Last Post: 09-16-2009, 05:45 AM
  5. What are Instance variables and static variables?
    By sandeshforu in forum New To Java
    Replies: 3
    Last Post: 09-09-2009, 05:48 PM

Posting Permissions

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