Class Menu

All Implemented Interfaces:
IRenderable, Tweenable, MouseListener, MouseMotionListener, MouseWheelListener, EventListener

public class Menu extends ImageComponentList
Represents a menu component that extends the ImageComponentList. This class provides functionality to create a menu with selectable items.
  • Constructor Details

    • Menu

      public Menu(double x, double y, double width, double height, Orientation orientation, String... items)
      Constructs a new Menu with the specified position, size, and orientation.
      Parameters:
      x - The x-coordinate of the menu.
      y - The y-coordinate of the menu.
      width - The width of the menu.
      height - The height of the menu.
      orientation - The orientation of the menu (horizontal or vertical).
      items - The items to be displayed in the menu.
    • Menu

      public Menu(double x, double y, double width, double height, String... items)
      Constructs a new Menu with the specified position, size, and items.
      Parameters:
      x - The x-coordinate of the menu.
      y - The y-coordinate of the menu.
      width - The width of the menu.
      height - The height of the menu.
      items - The items to be displayed in the menu.
    • Menu

      public Menu(double x, double y, double width, double height, Spritesheet background, Orientation orientation, String... items)
      Constructs a new Menu with the specified position, size, background, and orientation.
      Parameters:
      x - The x-coordinate of the menu.
      y - The y-coordinate of the menu.
      width - The width of the menu.
      height - The height of the menu.
      background - The background of the menu.
      orientation - The orientation of the menu (horizontal or vertical).
      items - The items to be displayed in the menu.
  • Method Details

    • getCurrentSelection

      public int getCurrentSelection()
      Gets the current selection index of the menu.
      Returns:
      The current selection index of the menu.
    • getOrientation

      public Orientation getOrientation()
      Gets the orientation of the menu.
      Returns:
      The orientation of the menu.
    • onChange

      public void onChange(IntConsumer cons)
      Adds a consumer that will be notified when the selection of the menu changes.
      Parameters:
      cons - The consumer that will be notified when the selection of the menu changes.
    • prepare

      public void prepare()
      Prepares the menu by setting the text of the menu buttons and adding the click listeners.
      Overrides:
      prepare in class ImageComponentList
    • setCurrentSelection

      public void setCurrentSelection(int newSelection)
      Sets the current selection index of the menu and updates the selection state of the menu items.
      Parameters:
      newSelection - The index of the item to be selected.