Results 1 to 6 of 6
  1. #1
    Join Date
    Jul 2013
    Posts
    2
    Rep Power
    0

    Default How to use variables from other .java file?

    So, I am editing the minecraft launcher, and I am trying to make a bit that saves the value typed into the JTextField() and the JPasswordField(). I am following a tutorial, and it says I should have a line of code like this to use another .java file's variables:

    Java Code:
    public static void main(String args[]){
        LoginForm lf = new LoginForm();
    }
    I am saving the data to the text file from another .java file because the LoginForm.java is very full and it is hard to work in.

    At the end of the LoginForm.java I have a bit that looks like this:

    Java Code:
    public JPasswordField getPassword() {
        return password;
      }
    
      public JTextField getUserName() {
        return userName;
      }
    However, that is not where my problem is. My problem is in WriteToFile.txt, on the bit that says
    Java Code:
    LoginForm lf = new LoginForm();
    When I hover over the error message on eclipse, it says:

    The constructor LoginForm() is undefined.

    I have no idea whatsoever why it says that. The tutorial has that line exactly in it.

  2. #2
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,001
    Rep Power
    6

    Default Re: How to use variables from other .java file?

    You have to learn Java, like this you can't be helped. Programming is hard, you can't do it by just guessing around and copy/pasting code from the net.

  3. #3
    Join Date
    Jul 2013
    Posts
    2
    Rep Power
    0

    Default Re: How to use variables from other .java file?

    Quote Originally Posted by gimbal2 View Post
    You have to learn Java, like this you can't be helped. Programming is hard, you can't do it by just guessing around and copy/pasting code from the net.
    Well thanks very much for helping me learn. A programming forum is meant for learning, not someone telling you to figure it out yourself.

  4. #4
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: How to use variables from other .java file?

    I think gimbal2 is trying to say, based on the questions you are asking you are at such an early stage of learning that a forum is really not the place for you.
    Have you gone through the basics of the oracle tutorials?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,001
    Rep Power
    6

    Default Re: How to use variables from other .java file?

    Quote Originally Posted by IntelligentTurtle View Post
    Well thanks very much for helping me learn. A programming forum is meant for learning, not someone telling you to figure it out yourself.
    That is what you make of it so it fits your needs, not what is necessarily the truth. What you are doing is going to a Spanish forum without learning the basics of the Spanish language first. You're not going to get anywhere, you're not in the position that someone can help you. You need to make a beginning yourself first.

    (So yes, Tolls was indeed correct)

  6. #6
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    12,006
    Rep Power
    20

    Default Re: How to use variables from other .java file?

    Quote Originally Posted by gimbal2 View Post
    (So yes, Tolls was indeed correct)
    ...there's a first...
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. File I/O: writing variables from another file
    By pondwire in forum New To Java
    Replies: 9
    Last Post: 07-31-2011, 11:11 PM
  2. remove variables/line in a text file
    By ddatta8 in forum New To Java
    Replies: 2
    Last Post: 01-04-2009, 03:05 AM
  3. append variables to a text file
    By ddatta8 in forum New To Java
    Replies: 2
    Last Post: 01-02-2009, 10:17 AM
  4. Replies: 4
    Last Post: 07-05-2008, 05:47 AM
  5. building file and variable names from variables
    By madad2005 in forum New To Java
    Replies: 2
    Last Post: 07-18-2007, 04:47 PM

Tags for this Thread

Posting Permissions

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