Results 1 to 5 of 5
  1. #1
    hungleon88 is offline Member
    Join Date
    Aug 2008
    Posts
    41
    Rep Power
    0

    Default take value other form

    I have a problem like this:
    I have a form LogIn with 2 textfileds Username and Password
    when i enter a correct username and password , application will hide a LogIn form and show form 2
    What i want to ask is how to take a Username value that i just entered in form LogIn and and set to the TextField in form 2 like " Welcome (username value from Log In form)" ?
    i tried:
    Form LogIn:
    public String user = UserName.getText();
    Form 2:
    LogIn log =new LogIn();
    textfield.setText(log.user);
    and that not work ! the textfield is blank...

    Help me !!

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

    Default

    by "Form" do you mean JFrame? Myself, I'd have a public method in the first class, the one responsible for handling your login GUI, something like so:
    Java Code:
      public String getUserName()
      {
         // assuming that this class has a private JTextField variable 
         // named userNameTextField 
         return userNameTextField.getText();
      }
    Then in the second class, when I wanted this data, I'd call this method on an instance of the first class (the instance that was displayed!).

  3. #3
    hungleon88 is offline Member
    Join Date
    Aug 2008
    Posts
    41
    Rep Power
    0

    Default

    oh thanks, i 'll try that, thanks for reply!

  4. #4
    hungleon88 is offline Member
    Join Date
    Aug 2008
    Posts
    41
    Rep Power
    0

    Default

    I already tried that, but did'nt work
    LogIn Form:
    private JTextField userName;
    public String getUsername()
    {
    return userName.getText();
    }

    SecondForm:
    LogIn log = new LogIn();
    JTextField.setText(log.getUsername());

    the text in the JtextField is blank T_T

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,455
    Rep Power
    20

    Default

    Well, if you've just instantiated the Login class, the userName JTextField is blank, isn't it? And that's where you're getting the text that you're setting to....

    Hey wait. setText isn't a static method, you can't invoke it on the class.

    Hop across to the Sun site and find the Swing tutorial. You need it badly.

    db

Similar Threads

  1. New to this form
    By talasilasumanth in forum Introductions
    Replies: 5
    Last Post: 10-30-2008, 01:34 PM
  2. enctype=multipart/form-data with form data in struts
    By vk_satheesh in forum New To Java
    Replies: 0
    Last Post: 09-19-2008, 01:48 PM
  3. how to read a form with JFS
    By crispy in forum JavaServer Faces (JSF)
    Replies: 2
    Last Post: 05-01-2008, 04:07 PM
  4. 1 form 2 servlets
    By sandor in forum Java Servlet
    Replies: 2
    Last Post: 01-22-2008, 11:47 AM
  5. Form Help Pls
    By CoOlbOyCoOl in forum NetBeans
    Replies: 4
    Last Post: 05-27-2007, 09:31 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
  •