I'm creating a GUI with Swing. First of all I instance the class User and I initialize it. Then, depending on Action Listeners I call methods of this class. The problem is that I have different functions in my class GUI and when I call the methods of the class I have to use the instance created in the beggining. The problem is that I cannot set the User class instance as an attribute of my class GUI because is not static.
public class User{
int id;
public User(){
id = 5;
}
public void setId(int a){
id = a;
}
}
public class Gui{
User u;
public static void main(String[] args){
u = new User();
////////////////
////////////////
doStuff();
}
public void doStuff() {
u.setId(1);
}
}
How could I do something like this?