Java repaint image -
i have problem script; want repaint new image (another 1 shown) when button pressed, button doesn't anything...
actionlistener 1 = new actionlistener() { public void actionperformed(actionevent e) { panel2.revalidate(); panel2.repaint(); } }; btn1.addactionlistener(one); jlabel test1 = new jlabel(mydeckofcards.givecardplayer1().getimage()); panel2.add(lab1); panel2.add(test1); panel2.add(pn5); panel2.add(pn1); panel2.add(btn1);
inside actionperformed
need hold of jlabel
, call seticon()
on it, passing in new image.
there's few ways jlabel, 1 make sure have final
variable declared contain somewhere in scope of actionperformed
method, , find inside panel2
(not recommended).
you pass in actionlistener
through constructor if declare full-fledged class purpose.
edit:
final jlabel test1 = new jlabel(mydeckofcards.givecardplayer1().getimage()); actionlistener 1 = new actionlistener() { public void actionperformed(actionevent e) { // 'anothericon' somewhere, presumably similar // place retrieved initial icon test1.seticon(anothericon); } }; btn1.addactionlistener(one); panel2.add(lab1); panel2.add(test1); panel2.add(pn5); panel2.add(pn1); panel2.add(btn1);
Comments
Post a Comment