LineEvent (Java SE 26 & JDK 26)
Description: declaration: module: java.desktop, package: javax.sound.sampled, class: LineEvent
Keywords: javax.sound.sampled.LineEvent class

# Class LineEvent

java.lang.Object
java.util.EventObject
javax.sound.sampled.LineEvent

All Implemented Interfaces:
  `Serializable`

public class LineEvent extends EventObject
The `LineEvent` class encapsulates information that a line sends its listeners whenever the line opens, closes, starts, or stops. Each of these four state changes is represented by a corresponding type of event. A listener receives the event as a parameter to its `update` method. By querying the event, the listener can learn the type of event, the line responsible for the event, and how much data the line had processed when the event occurred.

Although this class implements Serializable, attempts to serialize a `LineEvent` object will fail.

Since:
  1.3
See Also:
  - `Line`
  - `LineListener.update(LineEvent)`

- ## Nested Class Summary

  Nested Classes
  Modifier and Type
  Class
  Description
  `static class`
  `LineEvent.Type`
  The LineEvent.Type inner class identifies what kind of event occurred on a line.

- ## Field Summary

  ### Fields declared in class EventObject

  `source`
  Modifier and Type
  Field
  Description
  `protected Object`
  `source`
  The object on which the Event initially occurred.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `LineEvent(Line line, LineEvent.Type type, long position)`
  Constructs a new event of the specified type, originating from the specified line.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `final long`
  `getFramePosition()`
  Obtains the position in the line's audio data when the event occurred, expressed in sample frames.
  `final Line`
  `getLine()`
  Obtains the audio line that is the source of this event.
  `final LineEvent.Type`
  `getType()`
  Obtains the event's type.
  `String`
  `toString()`
  Returns a string representation of the event.

  ### Methods declared in class EventObject

  `getSource`
  Modifier and Type
  Method
  Description
  `Object`
  `getSource()`
  The object on which the Event initially occurred.

  ### Methods declared in class Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`
  Modifier and Type
  Method
  Description
  `protected Object`
  `clone()`
  Creates and returns a copy of this object.
  `boolean`
  `equals(Object obj)`
  Indicates whether some other object is "equal to" this one.
  `protected void`
  `finalize()`
  Deprecated, for removal: This API element is subject to removal in a future version.
  Finalization is deprecated and subject to removal in a future release.
  `final Class<?>`
  `getClass()`
  Returns the runtime class of this `Object`.
  `int`
  `hashCode()`
  Returns a hash code value for this object.
  `final void`
  `notify()`
  Wakes up a single thread that is waiting on this object's monitor.
  `final void`
  `notifyAll()`
  Wakes up all threads that are waiting on this object's monitor.
  `final void`
  `wait()`
  Causes the current thread to wait until it is awakened, typically by being notified or interrupted.
  `final void`
  `wait(long timeoutMillis)`
  Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
  `final void`
  `wait(long timeoutMillis, int nanos)`
  Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

- ## Constructor Details

  - ### LineEvent

    public LineEvent(Line line, LineEvent.Type type, long position)
    Constructs a new event of the specified type, originating from the specified line.
    Parameters:
      `line` - the source of this event
      `type` - the event type (`OPEN`, `CLOSE`, `START`, or `STOP`)
      `position` - the number of sample frames that the line had already processed when the event occurred, or `AudioSystem.NOT_SPECIFIED`
    Throws:
      `IllegalArgumentException` - if `line` is `null`

- ## Method Details

  - ### getLine

    public final Line getLine()
    Obtains the audio line that is the source of this event.
    Returns:
      the line responsible for this event

  - ### getType

    public final LineEvent.Type getType()
    Obtains the event's type.
    Returns:
      this event's type (`LineEvent.Type.OPEN`, `LineEvent.Type.CLOSE`, `LineEvent.Type.START`, or `LineEvent.Type.STOP`)

  - ### getFramePosition

    public final long getFramePosition()
    Obtains the position in the line's audio data when the event occurred, expressed in sample frames. For example, if a source line had already played back 14 sample frames at the time it was paused, the pause event would report the line's position as 14. The next frame to be processed would be frame number 14 using zero-based numbering, or 15 using one-based numbering.

    Note that this field is relevant only to certain events generated by data lines, such as `START` and `STOP`. For events generated by lines that do not count sample frames, and for any other events for which this value is not known, the position value should be `AudioSystem.NOT_SPECIFIED`.

    Returns:
      the line's position as a sample frame number

  - ### toString

    public String toString()
    Returns a string representation of the event.
    Overrides:
      `toString` in class `EventObject`
    Returns:
      a string representation of the event