i'm working on game can upgrade stats in shop. when buy should refresh jlabel shows coins
is there way without doing new jframe?
public void actionperformed(actionevent e) { user.setcoin(user.getcoin() - 5); user.setmaxjump(5); epixcontroller.getinstance().coinsupdate(user, -5); swingutilities.updatecomponenttreeui(epix); epix.revalidate(); epix.repaint(); }
this code of actionlistener want refresh jframe epix
here's code of view
public epixview(user user) { this.setuser(user); jframe epix = new jframe(); system.out.println(user.getmaxjump()); epix.setdefaultcloseoperation(jframe.exit_on_close); epix.setresizable(false); epix.setbounds(100, 100, 801, 523); epix.setlocationrelativeto(null); epix.getcontentpane().removeall(); /* * menucard */ menucard.setlayout(null); //coin menucardcoinimage.setbounds(0, 10, 64, 64); menucard.add(menucardcoinimage); menucardcoinimage.seticon(new imageicon(coinspinpath)); menucardcoinlabel = new jlabel("" + getuser().getcoin()); menucardcoinlabel.setfont(new font("modern no. 20", font.plain, 26)); menucardcoinlabel.setbounds(67, 10, 56, 64); menucard.add(menucardcoinlabel); //player menucardplayerlabel = new jlabel("willkommen zurück, " + getuser().getusername()); menucardplayerlabel.setbounds(598, 18, 239, 36); menucard.add(menucardplayerlabel); spielenbutton.setbounds(485, 319, 89, 23); menucard.add(spielenbutton); ranglistebutton.setbounds(485, 353, 89, 23); menucard.add(ranglistebutton); menucardbackgroundimage.seticon(new imageicon(backgroundpath)); menucardbackgroundimage.setbounds(0, 0, 801, 523); menucard.add(menucardbackgroundimage); cards.add(menucard, "menucard"); /* * upgradecard */ upgradecard.setlayout(null); //coin upgradecardcoinimage.setbounds(0, 10, 64, 64); upgradecardcoinimage.seticon(new imageicon(coinspinpath)); upgradecard.add(upgradecardcoinimage); upgradecardcoinlabel = new jlabel(""+ getuser().getcoin()); upgradecardcoinlabel.setbounds(67, 10, 56, 64); upgradecardcoinlabel.setfont(new font("modern no. 20", font.plain, 26)); upgradecard.add(upgradecardcoinlabel); //player upgradecardplayerlabel = new jlabel("willkommen zurück, " + getuser().getusername()); upgradecardplayerlabel.setbounds(598, 18, 239, 36); upgradecard.add(upgradecardplayerlabel); //maxhealthbar healthlabel.sethorizontalalignment(swingconstants.right); healthlabel.setbounds(191, 127, 110, 36); upgradecard.add(healthlabel); jprogressbar maxhealthbar = new jprogressbar(); maxhealthbar.setvalue(0); maxhealthbar.setbounds(327, 127, 185, 36); upgradecard.add(maxhealthbar); plushealthbutton.setbounds(522, 130, 41, 30); upgradecard.add(plushealthbutton); //maxjumpbar jumplabel.sethorizontalalignment(swingconstants.right); jumplabel.setbounds(191, 174, 110, 36); upgradecard.add(jumplabel); jprogressbar maxjumpbar = new jprogressbar(); maxjumpbar.setvalue(0); maxjumpbar.setbounds(327, 174, 185, 36); upgradecard.add(maxjumpbar); plusjumpbutton.setbounds(522, 177, 41, 30); plusjumpbutton.addactionlistener(new plusjumplistener(getuser(), maxjumpbar, epix)); upgradecard.add(plusjumpbutton); //maxspeed speedlabel.sethorizontalalignment(swingconstants.right); speedlabel.setbounds(191, 221, 110, 36); upgradecard.add(speedlabel); jprogressbar maxspeedbar = new jprogressbar(); maxspeedbar.setvalue(0); maxspeedbar.setbounds(327, 221, 185, 36); upgradecard.add(maxspeedbar); plusspeedbutton.setbounds(522, 224, 41, 30); upgradecard.add(plusspeedbutton); //damagebar damagelabel.sethorizontalalignment(swingconstants.right); damagelabel.setbounds(191, 268, 110, 36); upgradecard.add(damagelabel); jprogressbar damagebar = new jprogressbar(); damagebar.setvalue(0); damagebar.setbounds(327, 268, 185, 36); upgradecard.add(damagebar); plusdamagebutton.setbounds(522, 271, 41, 30); upgradecard.add(plusdamagebutton); levelauswählenbutton.setbounds(395, 361, 168, 30); upgradecard.add(levelauswählenbutton); upgradezurückbutton.setbounds(254, 361, 131, 30); upgradecard.add(upgradezurückbutton); upgradecardbackgroundimage.setbounds(0, 0, 801, 523); upgradecardbackgroundimage.seticon(new imageicon(backgroundpath)); upgradecard.add(upgradecardbackgroundimage); cards.add(upgradecard, "upgradecard"); /* * levelauswahlcard */ levelauswahlcard.setlayout(null); level1button.setbounds(67, 159, 171, 170); epixcontroller.getinstance().checklevelsaved(user, level1button); levelauswahlcard.add(level1button); level2button.setbounds(308, 159, 171, 170); epixcontroller.getinstance().checklevelsaved(user, level2button); levelauswahlcard.add(level2button); bosslevelbutton.setbounds(550, 159, 171, 170); epixcontroller.getinstance().checklevelsaved(user, bosslevelbutton); levelauswahlcard.add(bosslevelbutton); levelzurückbtton.setbounds(334, 378, 121, 28); levelauswahlcard.add(levelzurückbtton); levelauswahlcardcoinimage.setbounds(0, 10, 64, 64); levelauswahlcardcoinimage.seticon(new imageicon(coinspinpath)); levelauswahlcard.add(levelauswahlcardcoinimage); levelauswahlcardcoinlabel = new jlabel("" + getuser().getcoin()); levelauswahlcardcoinlabel.setbounds(67, 10, 56, 64); levelauswahlcardcoinlabel.setfont(new font("modern no. 20", font.plain, 26)); levelauswahlcard.add(levelauswahlcardcoinlabel); levelauswahlcardplayerlabel = new jlabel("willkommen zurück, " + getuser().getusername()); levelauswahlcardplayerlabel.setbounds(598, 18, 239, 36); levelauswahlcard.add(levelauswahlcardplayerlabel); levelauswahlcardbackgroundimage.seticon(new imageicon(backgroundpath)); levelauswahlcardbackgroundimage.setbounds(0, 0, 801, 523); levelauswahlcard.add(levelauswahlcardbackgroundimage); cards.add(levelauswahlcard, "levelauswahlcard"); /* * listener */ //menucard spielenbutton.addactionlistener(new menucardbuttonlistener(cards)); //upgradecard upgradezurückbutton.addactionlistener(new upgradecardbuttonlistener(cards)); levelauswählenbutton.addactionlistener(new upgradecardbuttonlistener(cards)); //levelauswahlcard levelzurückbtton.addactionlistener(new levelauswahlcardbuttonlistener(cards, getuser(), epix)); level1button.addactionlistener(new levelauswahlcardbuttonlistener(cards, getuser(), epix)); level2button.addactionlistener(new levelauswahlcardbuttonlistener(cards, getuser(), epix)); bosslevelbutton.addactionlistener(new levelauswahlcardbuttonlistener(cards, getuser(), epix)); epix.setcontentpane(cards); epix.setvisible(true); }
you don't have refresh frame or jpanel. in actionlistener have show cardlayout 'upgrade cards' have done in levelauswahllistener. should refresh it.
Comments
Post a Comment