Class ActionEvent

java.lang.Object
com.codename1.ui.events.ActionEvent
Direct Known Subclasses:
AsyncMedia.MediaErrorEvent, AsyncMedia.MediaStateChangeEvent, ComponentStateChangeEvent, MessageEvent, NetworkEvent, PluginEvent, WindowEvent

public class ActionEvent extends Object
Event object delivered when an ActionListener callback is invoked
  • 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
    • 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