Register action : Event Queue « Event « Java






Register action

  

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.Use the Event queue to retrieve eventUse the Event queue to retrieve event
2.Event object has information about an event, that has happened.
3.Register several listeners for one event.
4.ActionEvent.getActionCommand()
5.Adding an InputMap to a Component
6.Event source and listener
7.Multiple sources: A listener can be plugged into several sources.
8.Using an inner ActionListener class.
9.void java.awt.Toolkit.addAWTEventListener(AWTEventListener listener, long eventMask)
10.int java.awt.event.WindowEvent.WINDOW_OPENED
11.JComponent.WHEN_IN_FOCUSED_WINDOW
12.Using EventQueue.invokeLater to start a Swing application