I have a jframe that includes JButton.I have six buttons in this frame, but I don\'t know how to define action listener for this buttons.please help to solve this probl
It's really simple.
I suppose you have an instance of your button, right? Let's say that instance is called myButton
.
You can just add an action listener by calling addActionListener
:
myButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Do whatever you like here
}
});
Protip: next time you don't know what method to call, just type the instance name and .
. Then, your IDE will show you all the methods you can call, unless you are not using an IDE. If that is the case, download one.