how to display the string in the textfields

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pradeep84
    New Member
    • Sep 2007
    • 37

    #1

    how to display the string in the textfields

    Hi.. to all...
    in the following program i hav retrived data from the database and stored in the string s2,s3... now i hav display the following string in the textfields... i dont know how.. to do this... plz help me.........

    Regards
    pradeep

    Code:
    import java.awt.*;
    import java.sql.*;
    import java.awt.event.*;
    import sun.jdbc.odbc.*;
    import java.io.*;
    public class Viewcd extends Frame implements ActionListener
    {
         TextField ccod,cname,add,phno,conp,email,fax;
         Label l1,l2,l3,l4,l5,l6,l7;  
         Button view,back;
         String s1,s2,s3,s4,s5,s6,s7 ;
         
         Connection con;
         ResultSet rs;
         Statement stmt;
    public Viewcd()
    {
        super("VIEW ");
        setSize(600,700);
        setLayout(null);
        setBackground(new java.awt.Color(245, 117, 105));
        l1=new Label("ENTER THE CUSTOMERID");
        l2=new Label("CompanyName");
        l3=new Label("Address");
        l4=new Label("PhoneNumber");
        l5=new Label("Contact person");
        l6=new Label("EmailAddress");
        l7=new Label("FaxNumber");
        l1.setBounds(20,60,170,70);
        l2.setBounds(20,160,100,70);
        l3.setBounds(20,220,100,70);
        l4.setBounds(20,280,100,70);
        l5.setBounds(20,340,100,70);
        l6.setBounds(20,400,100,70);
        l7.setBounds(20,460,100,70);
        ccod=new TextField();
        cname=new TextField();
        add=new TextField();
        phno=new TextField();
        conp=new TextField();
        email=new TextField();
        fax=new TextField();
        ccod.setBounds(220,80,120,30);
        cname.setBounds(200,180,150,40);
        add.setBounds(200,240,150,40);
        phno.setBounds(200,300,150,40);
        conp.setBounds(200,360,150,40);
        email.setBounds(200,420,150,40);
        fax.setBounds(200,480,150,40);
        view= new Button("VIEW");
        back= new Button("BACK");
        view.setBounds(350,80,100,40);
        back.setBounds(460,80,100,40);
         view.addActionListener(this);
         back.addActionListener(this);
        add(l1);
        add(ccod);
        add(l2);
        add(cname);
        add(l3);
        add(add);
       add(l4);
       add(phno);
       add(l5);
       add(conp);
       add(l6);
       add(email);
       add(l7);
       add(fax);
       
        add(view);
        add(back);
      
       setVisible(true);
     
    addWindowListener(new WindowAdapter(){
      public void WindowClosing(WindowEvent w) {System.exit(0);}});
    }
     public void actionPerformed(ActionEvent ae)
    {
     int flag=0;
     if(ae.getSource()==view)
    {
         s1=ccod.getText();
    try 
    {
          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
          con=DriverManager.getConnection("jdbc:odbc:prism");
          stmt=con.createStatement(); 
          rs=stmt.executeQuery("select * from Customerdetails");
          while(rs.next())
         {
             if(rs.getString("CustomerID").equals(s1))
             {
    
    
               s1=(rs.getString(1));
               s2=(rs.getString(2));
               s3=(rs.getString(3));
               s4=(rs.getString(4));
               s5=(rs.getString(5));
               s6=(rs.getString(6));
               s7=(rs.getString(7));
                 
     }
    }
    }
    catch(ClassNotFoundException e)
    {
      System.out.println(e);
    }
    catch(SQLException e)
    {
      System.out.println(e);
    }
     }
     if(ae.getSource()==back)
    {
    
         this.hide();
         Customerdetails cd = new Customerdetails();
         
    }
    }
     
     public static void main(String args[]) 
    {
         
      Viewcd vd=new Viewcd();
    }
    }
  • beebob
    New Member
    • Sep 2007
    • 6

    #2
    hmm.. maybe you can try something like this:
    ...
    ccod.setText(s1 );
    ...
    Last edited by r035198x; Sep 26 '07, 06:46 AM. Reason: code tags bug had struck again

    Comment

    • madhoriya22
      Contributor
      • Jul 2007
      • 251

      #3
      Originally posted by pradeep84
      Hi.. to all...
      in the following program i hav retrived data from the database and stored in the string s2,s3... now i hav display the following string in the textfields... i dont know how.. to do this... plz help me.........

      Regards
      pradeep

      Code:
      
      
      Hi,
      I think this will be helpful for you ..

      Comment

      • beebob
        New Member
        • Sep 2007
        • 6

        #4
        hmm.. maybe you can try something like this:
        ...
        ccod.setText(s1 );
        ...


        regards,
        novan ananda

        Comment

        • pradeep84
          New Member
          • Sep 2007
          • 37

          #5
          Thank you... for your valuable suggestions.... .




          Regards
          Pradeep

          Comment

          • JosAH
            Recognized Expert MVP
            • Mar 2007
            • 11453

            #6
            Originally posted by pradeep84
            Thank you... for your valuable suggestions.... .
            Here's a little tip: before you start coding and using JComponents or other classes
            read their API documentation so you know what these things can do for you and
            what they can't do. If you didn't know you could set text in those JTextFields,
            why did you start using them anyway?

            So the steps to take are: read, design, implement, test, deliver. If you skip the
            first step(s) it'll be unlikely that you ever reach the last step.

            kind regards,

            Jos

            Comment

            Working...