Handling Action Events - Java Swing

Java examples for Swing:Event

Description

Handling Action Events

Demo Code


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();
  }
}

Related Tutorials