Class HealthBar

java.lang.Object
zero.community.HealthBar

public final class HealthBar extends Object
Presents app-owned health using ordinary JavaFX controls. Create and update this object on the JavaFX application thread. Each instance has its own view; a JavaFX node can be displayed in only one parent at a time.
  • Constructor Summary

    Constructors
    Constructor
    Description
    HealthBar(int maximum)
    Creates a full bar with the caption "Health".
    HealthBar(String caption, int maximum)
    Creates a full bar with an app-selected caption.
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Returns the last clamped displayed amount.
    int
    Returns this instance's positive maximum.
    void
    setHealth(int health)
    Explicitly updates the displayed amount; values are clamped to 0..maximum.
    javafx.scene.Node
    Returns this instance's stable ordinary JavaFX view.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • HealthBar

      public HealthBar(int maximum)
      Creates a full bar with the caption "Health".
      Parameters:
      maximum - positive maximum health
      Throws:
      IllegalArgumentException - if maximum is not positive
    • HealthBar

      public HealthBar(String caption, int maximum)
      Creates a full bar with an app-selected caption.
      Parameters:
      caption - non-null display caption
      maximum - positive maximum health
      Throws:
      NullPointerException - if caption is null
      IllegalArgumentException - if maximum is not positive
  • Method Details

    • view

      public javafx.scene.Node view()
      Returns this instance's stable ordinary JavaFX view.
      Returns:
      label and progress controls in a VBox
    • setHealth

      public void setHealth(int health)
      Explicitly updates the displayed amount; values are clamped to 0..maximum.
      Parameters:
      health - requested displayed health
    • getHealth

      public int getHealth()
      Returns the last clamped displayed amount.
      Returns:
      current health
    • getMaximum

      public int getMaximum()
      Returns this instance's positive maximum.
      Returns:
      maximum health