java - Updated Information In JFrame -
i have jframe "gamewindow" , class named "combat".
i trying update various components in gamewindow (jlabels, jprogressbars, etc.) variables in combat class. however, details never seem update. consider following:
public class combat { public static string attackname1; public static string punitname; public static void setplayerunit(gameunit u) { attackname1 = u.getattackname1(); punitname = u.getname().touppercase(); } }
and:
public gamewindow() { initialize(); gameframe.setvisible(true); } private void initialize() { gameframe = new jframe(); gameframe.setresizable(false); gameframe.settitle("gamewindow"); gameframe.setbounds(100, 100, 800, 480); gameframe.setdefaultcloseoperation(jframe.do_nothing_on_close); jbutton pattack1 = new jbutton(combat.attackname1); //<--------not being changed sl_gamepanel.putconstraint(springlayout.north, pattack1, 0, springlayout.north, gametextpanel); sl_gamepanel.putconstraint(springlayout.west, pattack1, 6, springlayout.east, textattackseparator); sl_gamepanel.putconstraint(springlayout.south, pattack1, 34, springlayout.north, gametextpanel); sl_gamepanel.putconstraint(springlayout.east, pattack1, 157, springlayout.east, textattackseparator); gamepanel.add(pattack1); jlabel pmobname = new jlabel(combat.punitname); //<--------not being changed sl_ppanel.putconstraint(springlayout.north, pmobname, 10, springlayout.north, ppanel); sl_ppanel.putconstraint(springlayout.west, pmobname, 129, springlayout.west, ppanel); ppanel.add(pmobname);
why text buttons/jlabels not being updated? need change using "combat.variable" "combat.getvariable()"? possible, , if so, how can make work?
you state:
jbutton pattack1 = new jbutton(combat.attackname1); stated, text on jbutton not updated when changing variable in combat class.
you're confusing reference variable object represents , need understand different. while combat.attackname1 , jbutton's name refer same string object, strings immutable. when change string object variable referring have no effect on string displayed jbutton. solution: call jbutton's settext(...)
method if want change displayed text.
Comments
Post a Comment