java - Forcing a JPanel to repaint after calling the show method of CardLayout -


i'm writing holiday recommendation system piece of coursework. gui of uses cardlayout. in main class user object created default name , access levels defined in it's constructor. object passed main usercard panel passes login , logged in. if user logs in cardpanel transitions login logged in , supposed display username of logged in user calling user.getusername(); method.

my problem thus. because of way card layout works panel username display has been created in constructor of usercards default values user object first created. need find way force panel repaint after show method called on cardlayout object. following code of 3 classes in question. (i've limited code paste relevant methods).

//the usercards panel          public usercards(user u)     {         cardlayout cl = new cardlayout();         this.setlayout(cl);          useroptionspanel options_card = new useroptionspanel(cl, this);         registerpanel register_card = new registerpanel(cl, this);         loggedinpanel loggedin_card = new loggedinpanel(cl, this, u);         loginpanel login_card = new loginpanel(cl, this, u, loggedin_card);          this.add(options_card, options);         this.add(login_card, login);         this.add(register_card, register);         this.add(loggedin_card, loggedin);     }  //the loggin action listener user passed in reference user object created in //main. createuser(); method badly named method calls setter methods on //the user object's fields      @override     public void actionperformed(actionevent e)      {         string[] vals = packdata();         try         {             dbconnection d = new dbconnection();             connection conn = d.getconnection();             validation v = new validation(vals, user);             v.getactual(conn);             if(v.validate())             {                 user = v.createuser();                 system.out.println(user.getusername());                 l.revalidate();                 cl.show(pane, "loggedin");             }             else             {                 lbl_statusmsg.settext("password incorrect");                 lbl_statusmsg.repaint();             }          }         catch(classnotfoundexception | sqlexception ex)         {             ex.printstacktrace();         }     }  //the loggedin constructor  public class loggedinpanel extends jpanel {     private user user;     private jlabel lbl_details;     public loggedinpanel(cardlayout cl, container pane, user u)     {         super();         user = u;         this.setlayout(new boxlayout(this, boxlayout.y_axis));          lbl_details = new jlabel();         lbl_details.settext("welcome "+user.getusername());          this.add(lbl_details);     }     } 

apologies if i've not been overly clear i'm not given asking :)

do mean ?

cardlayout cl = new cardlayout() {   @override   public void show(java.awt.container parent, string name) {     super.show(parent, name);     // code here    } }; 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -