What you need is to pass it to File2.java
, so assuming that you have something like so:
public class File2
{
...
//Constructor
public File2(...)
...
}
You would need to change it like so:
public class File2
{
....
String userName = "";
public File2(...String userName...)
{
this.userName = userName;
...
}
....
}
And call it like so (from your File1
class):
String user = jTextField1.getText();
...
File2 file2 = new File2(..., user, ...);
Alternatively, instead of passing the userName
field, you can pass an instance of File1
to your File2
class and expose whatever fields you want to access through Field2
by creating the appropriate get
methods in your File1
class. This usually comes in handy when you need to access more than one field.