Module javafx.graphics
Package javafx.animation

# Class KeyFrame

java.lang.Object
javafx.animation.KeyFrame

    public final class KeyFrame
    extends Object

Defines target values at a specified point in time for a set of variables that are interpolated along a `Timeline`.

The developer controls the interpolation of a set of variables for the interval between successive key frames by providing a target value and an `Interpolator` associated with each variable. The variables are interpolated such that they will reach their target value at the specified time. An `onFinished` function is invoked on each `KeyFrame` if one is provided. A `KeyFrame` can optionally have a `name`, which will result in a cuepoint that is automatically added to the `Timeline`.

Since:
  JavaFX 2.0
See Also:
  `Timeline`, `KeyValue`, `Interpolator`

- ## Constructor Summary

  Constructors
  Constructor | Description
  --- | ---
  `KeyFrame​(Duration time, String name, KeyValue... values)` | Constructor of `KeyFrame`
  `KeyFrame​(Duration time, String name, EventHandler<ActionEvent> onFinished, Collection<KeyValue> values)` | Constructor of `KeyFrame`
  `KeyFrame​(Duration time, String name, EventHandler<ActionEvent> onFinished, KeyValue... values)` | Constructor of `KeyFrame`
  `KeyFrame​(Duration time, KeyValue... values)` | Constructor of `KeyFrame`
  `KeyFrame​(Duration time, EventHandler<ActionEvent> onFinished, KeyValue... values)` | Constructor of `KeyFrame`

- ## Method Summary

  Modifier and Type | Method | Description
  --- | --- | ---
  `boolean` | `equals​(Object obj)` | Indicates whether some other object is "equal to" this one.
  `String` | `getName()` | Returns the `name` of this `KeyFrame`.
  `EventHandler<ActionEvent>` | `getOnFinished()` | Returns the `onFinished` event handler of this `KeyFrame`.
  `Duration` | `getTime()` | Returns the time offset of this `KeyFrame`.
  `Set<KeyValue>` | `getValues()` | Returns an immutable `Set` of `KeyValue` instances.
  `int` | `hashCode()` | Returns a hash code for this `KeyFrame` object.
  `String` | `toString()` | Returns a string representation of this `KeyFrame` object.

  ### Methods declared in class java.lang.Object

  `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- ## Constructor Details

  - ### KeyFrame

    public KeyFrame​(Duration time, String name, EventHandler<ActionEvent> onFinished, Collection<KeyValue> values)
    Constructor of `KeyFrame`

    If a passed in `KeyValue` is `null` or a duplicate, it will be ignored.

    Parameters:
      `time` - the `time`
      `name` - the `name`
      `onFinished` - the `onFinished`
      `values` - a `ObservableList` of `KeyValue` instances
    Throws:
      `NullPointerException` - if `time` is null
      `IllegalArgumentException` - if `time` is invalid (see `time`)

  - ### KeyFrame

    public KeyFrame​(Duration time, String name, EventHandler<ActionEvent> onFinished, KeyValue... values)
    Constructor of `KeyFrame`

    If a passed in `KeyValue` is `null` or a duplicate, it will be ignored.

    Parameters:
      `time` - the `time`
      `name` - the `name`
      `onFinished` - the `onFinished`
      `values` - the `KeyValue` instances
    Throws:
      `NullPointerException` - if `time` is null
      `IllegalArgumentException` - if `time` is invalid (see `time`)

  - ### KeyFrame

    public KeyFrame​(Duration time, EventHandler<ActionEvent> onFinished, KeyValue... values)
    Constructor of `KeyFrame`
    Parameters:
      `time` - the `time`
      `onFinished` - the `onFinished`
      `values` - the `KeyValue` instances
    Throws:
      `NullPointerException` - if `time` is null
      `IllegalArgumentException` - if `time` is invalid (see `time`)

  - ### KeyFrame

    public KeyFrame​(Duration time, String name, KeyValue... values)
    Constructor of `KeyFrame`
    Parameters:
      `time` - the `time`
      `name` - the `name`
      `values` - the `KeyValue` instances
    Throws:
      `NullPointerException` - if `time` is null
      `IllegalArgumentException` - if `time` is invalid (see `time`)

  - ### KeyFrame

    public KeyFrame​(Duration time, KeyValue... values)
    Constructor of `KeyFrame`
    Parameters:
      `time` - the `time`
      `values` - the `KeyValue` instances
    Throws:
      `NullPointerException` - if `time` is null
      `IllegalArgumentException` - if `time` is invalid (see `time`)

- ## Method Details

  - ### getTime

    public Duration getTime()
    Returns the time offset of this `KeyFrame`. The returned `Duration` defines the time offset within a single cycle of a `Timeline` at which the `KeyValues` will be set and at which the `onFinished` function variable will be called.

    The `time` of a `KeyFrame` has to be greater than or equal to `Duration.ZERO` and it cannot be `Duration.UNKNOWN`. Note: While the unit of `time` is a millisecond, the granularity depends on the underlying operating system and will in general be larger. For example animations on desktop systems usually run with a maximum of 60fps which gives a granularity of ~17 ms.

    Returns:
      the time offset

  - ### getValues

    public Set<KeyValue> getValues()
    Returns an immutable `Set` of `KeyValue` instances. A `KeyValue` defines a target and the desired value that should be interpolated at the specified time of this `KeyFrame`.
    Returns:
      an immutable `Set` of `KeyValue` instances

  - ### getOnFinished

    public EventHandler<ActionEvent> getOnFinished()
    Returns the `onFinished` event handler of this `KeyFrame`. The `onFinished` event handler is a function that is called when the elapsed time on a cycle passes the specified time of this `KeyFrame`. The `onFinished` function variable will be called if the elapsed time passes the indicated value, even if it never equaled the time value exactly.
    Returns:
      the `onFinished` event handler

  - ### getName

    public String getName()
    Returns the `name` of this `KeyFrame`. If a named `KeyFrame` is added to a `Timeline`, a cuepoint with the `name` and the `time` of the `KeyFrame` will be added automatically. If the `KeyFrame` is removed, the cuepoint will also be removed.
    Returns:
      the `name`

  - ### toString

    public String toString()
    Returns a string representation of this `KeyFrame` object.
    Overrides:
      `toString` in class `Object`
    Returns:
      the string representation

  - ### hashCode

    public int hashCode()
    Returns a hash code for this `KeyFrame` object.
    Overrides:
      `hashCode` in class `Object`
    Returns:
      the hash code

  - ### equals

    public boolean equals​(Object obj)
    Indicates whether some other object is "equal to" this one. Two `KeyFrames` are considered equal, if their `time`, `onFinished`, and `values` are equal.
    Overrides:
      `equals` in class `Object`
    Returns:
      `true` if this is the same as obj, otherwise `false`