# Class ActionEvent

java.lang.Object
com.codename1.ui.events.ActionEvent

Direct Known Subclasses:
  `AsyncMedia.MediaErrorEvent, AsyncMedia.MediaStateChangeEvent, ComponentStateChangeEvent, MessageEvent, NetworkEvent, PluginEvent, WheelEvent, WindowEvent`

public class ActionEvent extends Object
Event object delivered when an `ActionListener` callback is invoked

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static enum`
  `ActionEvent.Type`
  The event type, as declared when the event is created.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ActionEvent(Command source, Component sourceComponent, int x, int y)`
  Creates a new instance of ActionEvent for a command
  `ActionEvent(Command source, ActionEvent.Type type, Component sourceComponent, int x, int y)`
  Creates a new instance of ActionEvent for a command
  `ActionEvent(Component dragged, Component drop, int x, int y)`
  Creates a new instance of ActionEvent for a drop operation
  `ActionEvent(Component dragged, ActionEvent.Type type, Component drop, int x, int y)`
  Creates a new instance of ActionEvent for a drop operation
  `ActionEvent(Object source)`
  Creates a new instance of ActionEvent.
  `ActionEvent(Object source, int keyEvent)`
  Creates a new instance of ActionEvent
  `ActionEvent(Object source, int keyEvent, boolean longClick)`
  Creates a new instance of ActionEvent
  `ActionEvent(Object source, int x, int y)`
  Creates a new instance of ActionEvent as a generic pointer event.
  `ActionEvent(Object source, int x, int y, boolean longPointer)`
  Creates a new instance of ActionEvent as a pointer event
  `ActionEvent(Object source, ActionEvent.Type type)`
  Creates a new instance of ActionEvent
  `ActionEvent(Object source, ActionEvent.Type type, int keyEvent)`
  Creates a new instance of ActionEvent.
  `ActionEvent(Object source, ActionEvent.Type type, int x, int y)`
  Creates a new instance of ActionEvent as a pointer event

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `consume()`
  Consume the event indicating that it was handled thus preventing other action listeners from handling/receiving the event
  `Component`
  `getActualComponent()`
  Identical to `ActionEvent#getComponent()` except for the fact that a lead component will be returned if such a lead component is available.
  `Command`
  `getCommand()`
  If this event was sent as a result of a command action this method returns that command
  `Component`
  `getComponent()`
  Returns the component that generated the event.
  `Component`
  `getDraggedComponent()`
  Set in the case of a drop listener, returns the component being dragged
  `Component`
  `getDropTarget()`
  Set in the case of a drop listener, returns the component on which the drop occurs
  `ActionEvent.Type`
  `getEventType()`
  Returns the type of the given event allowing us to have more generic event handling code and useful for debugging
  `int`
  `getKeyEvent()`
  If this event was triggered by a key press this method will return the appropriate keycode
  `PointerEvent`
  `getPointerEvent()`
  Returns the rich pointer detail for this event such as the triggering mouse button, the pointing device type (finger, mouse, stylus or eraser), the pressure applied and the stylus tilt.
  `int`
  `getProgress()`
  Returns the numeric progress of native browser loading on Android
  `Object`
  `getSource()`
  The element that triggered the action event, useful for decoupling event handling code
  `int`
  `getX()`
  The X position if this is a pointer event otherwise undefined
  `int`
  `getY()`
  The Y position if this is a pointer event otherwise undefined
  `boolean`
  `isConsumed()`
  Returns true if the event was consumed thus indicating that it was handled.
  `boolean`
  `isLongEvent()`
  Returns true for long click or long pointer event
  `boolean`
  `isPointerPressedDuringDrag()`
  Only used for pointer dragged events.
  `void`
  `setPointerEvent(PointerEvent pointerEvent)`
  Attaches an explicit rich pointer detail snapshot to this event.
  `void`
  `setPointerPressedDuringDrag(boolean pressed)`
  Only used for pointer dragged events.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### ActionEvent

    public ActionEvent(Object source)

    Creates a new instance of ActionEvent. This is unused locally, but provided so existing customer code with still work.

    ###### Parameters

    - `source`: element for the action event

  - ### ActionEvent

    public ActionEvent(Object source, ActionEvent.Type type)

    Creates a new instance of ActionEvent

    ###### Parameters

    - `source`: element for the action event

    - `type`: the `Type` of the event

  - ### ActionEvent

    public ActionEvent(Object source, ActionEvent.Type type, int x, int y)

    Creates a new instance of ActionEvent as a pointer event

    ###### Parameters

    - `source`: element for the pointer event

    - `type`: the `Type` of the event

    - `x`: (or sometimes width) associated with the event

    - `y`: (or sometimes height)associated with the event

  - ### ActionEvent

    public ActionEvent(Command source, ActionEvent.Type type, Component sourceComponent, int x, int y)

    Creates a new instance of ActionEvent for a command

    ###### Parameters

    - `source`: element command

    - `type`: the `Type` of the event

    - `sourceComponent`: the triggering component

    - `x`: the x position of the pointer event

    - `y`: the y position of the pointer event

  - ### ActionEvent

    public ActionEvent(Component dragged, ActionEvent.Type type, Component drop, int x, int y)

    Creates a new instance of ActionEvent for a drop operation

    ###### Parameters

    - `dragged`: the dragged component

    - `type`: the `Type` of the event

    - `drop`: the drop target component

    - `x`: the x position of the pointer event

    - `y`: the y position of the pointer event

  - ### ActionEvent

    public ActionEvent(Object source, ActionEvent.Type type, int keyEvent)

    Creates a new instance of ActionEvent. The key event is really just a numeric code, not indicative of a key press

    ###### Parameters

    - `source`: element for the action event

    - `type`: the `Type` of the event

    - `keyEvent`: the key that triggered the event

  - ### ActionEvent

    public ActionEvent(Object source, int keyEvent)

    Creates a new instance of ActionEvent

    ###### Parameters

    - `source`: element for the action event

    - `keyEvent`: the key that triggered the event

  - ### ActionEvent

    public ActionEvent(Object source, int keyEvent, boolean longClick)

    Creates a new instance of ActionEvent

    ###### Parameters

    - `source`: element for the action event

    - `keyEvent`: the key that triggered the event

    - `longClick`: true if the event is triggered from long pressed

  - ### ActionEvent

    public ActionEvent(Object source, int x, int y, boolean longPointer)

    Creates a new instance of ActionEvent as a pointer event

    ###### Parameters

    - `source`: element for the pointer event

    - `x`: the x position of the pointer event

    - `y`: the y position of the pointer event

    - `longPointer`: true if the event is triggered from long pressed

  - ### ActionEvent

    public ActionEvent(Object source, int x, int y)

    Creates a new instance of ActionEvent as a generic pointer event.

    ###### Parameters

    - `source`: element for the pointer event

    - `x`: the x position of the pointer event

    - `y`: the y position of the pointer event

  - ### ActionEvent

    public ActionEvent(Command source, Component sourceComponent, int x, int y)

    Creates a new instance of ActionEvent for a command

    ###### Parameters

    - `source`: element command

    - `sourceComponent`: the triggering component

    - `x`: the x position of the pointer event

    - `y`: the y position of the pointer event

  - ### ActionEvent

    public ActionEvent(Component dragged, Component drop, int x, int y)

    Creates a new instance of ActionEvent for a drop operation

    ###### Parameters

    - `dragged`: the dragged component

    - `drop`: the drop target component

    - `x`: the x position of the pointer event

    - `y`: the y position of the pointer event

- ## Method Details

  - ### getEventType

    public ActionEvent.Type getEventType()

    Returns the type of the given event allowing us to have more generic event handling code and useful for debugging

    ###### Returns

    the Type enum

  - ### getSource

    public Object getSource()

    The element that triggered the action event, useful for decoupling event handling code

    ###### Returns

    the element that triggered the action event

  - ### getKeyEvent

    public int getKeyEvent()

    If this event was triggered by a key press this method will return the appropriate keycode

    ###### Returns

    the key that triggered the event

  - ### getProgress

    public int getProgress()

    Returns the numeric progress of native browser loading on Android

    ###### Returns

    the progress value

  - ### getCommand

    public Command getCommand()

    If this event was sent as a result of a command action this method returns that command

    ###### Returns

    the command action that triggered the action event

  - ### getActualComponent

    public Component getActualComponent()

    Identical to `ActionEvent#getComponent()` except for the fact that a lead component will be returned if such a lead component is available. This is important for components such as `com.codename1.components.MultiButton` which will return the underlying button instead.

    ###### Returns

    the component that sent the event

  - ### getComponent

    public Component getComponent()

    Returns the component that generated the event. important this might not be the actual component. In case of a lead component such as `com.codename1.components.MultiButton` the underlying `com.codename1.ui.Button` will be returned and not the `com.codename1.components.MultiButton` itself. To get the component that you would logically think of as the source component use the `#getActualComponent` method.

    If you are in doubt use the `getActualComponent` method.

    ###### Returns

    a component

    ###### See also

    - ActionEvent#getActualComponent() - you should probably use `getActualComponent` instead of this method

  - ### consume

    public void consume()
    Consume the event indicating that it was handled thus preventing other action listeners from handling/receiving the event

  - ### isConsumed

    public boolean isConsumed()

    Returns true if the event was consumed thus indicating that it was handled. This prevents other action listeners from handling/receiving the event

    ###### Returns

    true if the event was consumed

  - ### getX

    public int getX()

    The X position if this is a pointer event otherwise undefined

    ###### Returns

    x position

  - ### getY

    public int getY()

    The Y position if this is a pointer event otherwise undefined

    ###### Returns

    y position

  - ### isLongEvent

    public boolean isLongEvent()
    Returns true for long click or long pointer event

  - ### getPointerEvent

    public PointerEvent getPointerEvent()

    Returns the rich pointer detail for this event such as the triggering mouse button, the pointing device type (finger, mouse, stylus or eraser), the pressure applied and the stylus tilt. For pointer events that did not have an explicit snapshot attached this falls back to the pointer event currently being dispatched, so the detail is available from any pointer listener. Returns null for non pointer events.

    ###### Returns

    the `PointerEvent` detail or null when this is not a pointer event

  - ### setPointerEvent

    public void setPointerEvent(PointerEvent pointerEvent)

    Attaches an explicit rich pointer detail snapshot to this event.

    ###### Parameters

    - `pointerEvent`: the snapshot to attach

  - ### getDraggedComponent

    public Component getDraggedComponent()

    Set in the case of a drop listener, returns the component being dragged

    ###### Returns

    the component being dragged

  - ### getDropTarget

    public Component getDropTarget()

    Set in the case of a drop listener, returns the component on which the drop occurs

    ###### Returns

    the component on which the drop occurs

  - ### isPointerPressedDuringDrag

    public boolean isPointerPressedDuringDrag()

    Only used for pointer dragged events. This flag is set to true if a pointer press event was silently swallowed by a drag in progress. While dragging and scrolling is in progress, pointer pressed events are not delivered. This allows you to detect if a pointer press occurred during a scroll or drag.

    ###### Since

    8.0

  - ### setPointerPressedDuringDrag

    public void setPointerPressedDuringDrag(boolean pressed)

    Only used for pointer dragged events. This flag is set to true if a pointer press event was silently swallowed by a drag in progress. While dragging and scrolling is in progress, pointer pressed events are not delivered. This allows you to detect if a pointer press occurred during a scroll or drag.

    ###### Since

    8.0