Example usage for java.awt.event ActionEvent ActionEvent

List of usage examples for java.awt.event ActionEvent ActionEvent

Introduction

In this page you can find the example usage for java.awt.event ActionEvent ActionEvent.

Prototype

public ActionEvent(Object source, int id, String command, int modifiers) 

Source Link

Document

Constructs an ActionEvent object with modifier keys.

Usage

From source file:Main.java

public static boolean invoke(Action action, Object source) {
    if (action == null || !action.isEnabled()) {
        return false;
    }//from   w ww  . j av a 2s .  c  om
    ActionEvent evt = new ActionEvent(source, ActionEvent.ACTION_PERFORMED,
            (String) action.getValue(Action.ACTION_COMMAND_KEY), 0);
    action.actionPerformed(evt);
    return true;
}

From source file:Main.java

public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand() != null) {
        String command = e.getActionCommand();
        if (command != null) {
            command = command.toUpperCase();
        }//from   ww w.  j  ava  2 s.c  o  m
        e = new ActionEvent(e.getSource(), e.getID(), command, e.getModifiers());
    }

    if (defAction != null) {
        defAction.actionPerformed(e);
    }
}

From source file:Main.java

public KeyTextComponent() {
    setBackground(Color.CYAN);//from   ww w.  j  av a 2 s .c  o  m
    KeyListener internalKeyListener = new KeyAdapter() {
        public void keyPressed(KeyEvent keyEvent) {
            if (actionListenerList != null) {
                int keyCode = keyEvent.getKeyCode();
                String keyText = KeyEvent.getKeyText(keyCode);
                ActionEvent actionEvent = new ActionEvent(this, ActionEvent.ACTION_FIRST, keyText,
                        ActionEvent.ALT_MASK);
                fireActionPerformed(actionEvent);
            }
        }
    };

    MouseListener internalMouseListener = new MouseAdapter() {
        public void mousePressed(MouseEvent mouseEvent) {
            requestFocusInWindow();
        }
    };

    addKeyListener(internalKeyListener);
    addMouseListener(internalMouseListener);
}