ActionMap javax.swing.JComponent.getActionMap() : Customized Event « Event « Java






ActionMap javax.swing.JComponent.getActionMap()

  

import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;

public class Main {
  public static void main(String[] argv) throws Exception {
    JButton component = new JButton();
    MyAction action = new MyAction();

    component.getActionMap().put(action.getValue(Action.NAME), action);
  }
}

class MyAction extends AbstractAction {
  public MyAction() {
    super("my action");
  }

  public void actionPerformed(ActionEvent e) {
    System.out.println("hi");

  }
}

   
    
  








Related examples in the same category

1.Customized Event Customized Event
2.Removing listeners: remove the registered listeners.
3.implements AWTEventListener
4.int java.awt.AWTEvent.getID()
5.Creating a Custom Event
6.implements ActionListener to create action class