How do I see if a button with an imageIcon loaded has been pressed in java? -
i have program have settings button. button has image icon shows image. tips on how can preform action when pressed. here code
jbutton imagebutton = new jbutton(new imageicon("/users/sam/programming/files/gears.png"));
it works fine. when want use
else if(ae.getactioncommand().equals(imagebutton)){//dostuff}
it doesnt work. action preformed method works, here is
public void actionperformed(actionevent ae) {}
your actionlisterner not responding because getactioncommand() should return string. in case should name of jbutton.
else if(ae.getactioncommand().equals(imagebutton.gettext())){//dostuff}
changing imagebutton.gettext() should solve problem.
if not sure, manually set actioncommand through setactioncommand() , use same string verify getactioncommand in .equals() method.
Comments
Post a Comment