java - How to detect when a JButton is pressed (swing)? -
in java's swing package, wondering how detect when jbutton pressed. there function called when button pressed? thanks
yes, when deal button pressing, want add known action listener. first, must
import java.awt.event.actionlistener;
then can following
button.addactionlistener(new actionlistener() { public void actionperformed(actionevent e) { // makes sure button pressing button variable if(e.getsource() == button) { // action necessary code } } });
Comments
Post a Comment