java - Editing JLabel from JTextField in another class -


i've looked around nothing seems me out. i'm writing multithreaded chat program gui. user inputs name in textfield in login class , hits login button directs him clientgui class. in client gui class theres jlabel @ top says

"welcome chatsystem (username)"

. user input in textfield in login class should appear in jlabel after "welcome chatsystem" can't figure out why doesn't work. here's code:

login class:

loginb = new jbutton("login"); main.add(loginb); loginb.addactionlistener(new actionlistener(){     @override     public void actionperformed(actionevent e) {         clientgui clientgui = new clientgui();         clientgui.setvisible(true);     } } 

clientgui class:

public clientgui(){     login login = new login();     string username = login.usernametf.gettext();     welcome = new jlabel("welcome chatsystem "+username, swingconstants.center);  } 

i understand username should jlabel , not string have tried many ways , can't seem head around this.

that not going work because login.usernametf.gettext(); new created object in clientgui constructor...

what suggest overload constructor , pass name parameter...

example:

 loginb.addactionlistener(new actionlistener(){      @override      public void actionperformed(actionevent e) {      clientgui clientgui = new clientgui(getthenameandpassithere);      clientgui.setvisible(true);             }         } 

and clientgui class:

public clientgui(string username){      //login login = new login();    // string username = login.usernametf.gettext();      welcome = new jlabel("welcome chatsystem "+username, swingconstants.center);  } 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -