Java examples for Swing:Event
Handling Action Events
import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.AbstractButton; import javax.swing.JButton; public class Main { public static void main(String[] argv) { AbstractButton button = new JButton("OK"); button.addActionListener(new MyActionListener()); }//www .j a va 2 s . co m } class MyActionListener implements ActionListener { public void actionPerformed(ActionEvent evt) { // Determine which abstract button fired the event. AbstractButton button = (AbstractButton) evt.getSource(); } }