Class Window

java.lang.Object
org.openpatch.scratch.Window

public class Window extends Object
The Window class represents a singleton window for the application. It provides various constructors to create a window with different configurations such as dimensions, full screen mode, and asset paths. The class ensures that only one instance of the window can be created at any time.

The class also provides methods to interact with the window and the application, such as retrieving the window dimensions, setting the debug mode, managing stages, and exiting the application.

Example usage:


 Window window = new Window();
 window.setDebug(true);
 
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int[]
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructs a new Window with default dimensions.
    Window(boolean fullScreen)
    Constructs a new Window.
    Window(boolean fullScreen, String assets)
    Constructs a new Window instance.
    Window(int width, int height)
    Constructs a new Window with the specified width and height.
    Window(int width, int height, String assets)
    Constructs a new Window with the specified width, height, and assets path.
    Window(String assets)
    Constructs a new Window with the specified assets.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    addStage(String name, Stage stage)
    Deprecated.
    since 4.0.0.
    void
    Exits the application by invoking the `whenExits` method and then calling the `exit` method on the `Applet` instance.
    double
    Gets the seconds passed since the last frame.
    int
    Retrieves the height of the current window.
    static Window
    Returns the singleton instance of the Window class.
    Retrieves the current stage from the Applet instance.
    int
    Retrieves the width of the current window.
    boolean
    Checks if the application is in debug mode.
    void
    Deprecated.
    since 4.0.0.
    void
    setDebug(boolean debug)
    Enables or disables the debug mode for the application.
    void
    Sets the default font for the application.
    void
    setStage(Stage stage)
    Sets the current stage of the application.
    void
    Deprecated.
    since 4.0.0.
    void
    This method is called when the window exits.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEBUG_COLOR

      public static final int[] DEBUG_COLOR
  • Constructor Details

    • Window

      public Window()
      Constructs a new Window with default dimensions. The default width is 480 pixels and the default height is 360 pixels.
    • Window

      public Window(String assets)
      Constructs a new Window with the specified assets. The window will have a default width of 480 pixels and a height of 360 pixels.
      Parameters:
      assets - the path to the assets to be used in the window
    • Window

      public Window(int width, int height)
      Constructs a new Window with the specified width and height.
      Parameters:
      width - the width of the window
      height - the height of the window
    • Window

      public Window(int width, int height, String assets)
      Constructs a new Window with the specified width, height, and assets path. Ensures that only one instance of Window can be created.
      Parameters:
      width - the width of the window
      height - the height of the window
      assets - the path to the assets
      Throws:
      Error - if an instance of Window already exists
    • Window

      public Window(boolean fullScreen)
      Constructs a new Window.
      Parameters:
      fullScreen - a boolean indicating whether the window should be in full screen mode.
    • Window

      public Window(boolean fullScreen, String assets)
      Constructs a new Window instance. If an instance of Window already exists, an Error is thrown to ensure only one Window instance is created.
      Parameters:
      fullScreen - a boolean indicating whether the window should be in full screen mode
      assets - a String specifying the path to the assets
      Throws:
      Error - if an instance of Window already exists
  • Method Details

    • getInstance

      public static Window getInstance()
      Returns the singleton instance of the Window class.
      Returns:
      the singleton instance of Window
    • getDeltaTime

      public double getDeltaTime()
      Gets the seconds passed since the last frame.
      Returns:
      seconds since last frame
    • isDebug

      public boolean isDebug()
      Checks if the application is in debug mode.
      Returns:
      true if the application is in debug mode, false otherwise.
    • setDebug

      public void setDebug(boolean debug)
      Enables or disables the debug mode for the application.
      Parameters:
      debug - a boolean value where true enables debug mode and false disables it.
    • getWidth

      public int getWidth()
      Retrieves the width of the current window.
      Returns:
      the width of the window in pixels
    • getHeight

      public int getHeight()
      Retrieves the height of the current window.
      Returns:
      the height of the window in pixels
    • setDefaultFont

      public void setDefaultFont(String path)
      Sets the default font for the application.
      Parameters:
      path - the file path to the font to be set as default
    • setStage

      public void setStage(Stage stage)
      Sets the current stage of the application.
      Parameters:
      stage - the new stage to be set
    • addStage

      @Deprecated(since="4.0.0") public void addStage(String name, Stage stage)
      Deprecated.
      since 4.0.0. Use setStage instead.
      Parameters:
      name - Name of the stage
      stage - A stage object
    • switchStage

      @Deprecated(since="4.0.0") public void switchStage(String name)
      Deprecated.
      since 4.0.0. Use setStage instead.
      Parameters:
      name - Name of the stage
    • removeStage

      @Deprecated(since="4.0.0") public void removeStage(String name)
      Deprecated.
      since 4.0.0. Use setStage instead.
      Parameters:
      name - Name of the stage
    • getStage

      public Stage getStage()
      Retrieves the current stage from the Applet instance.
      Returns:
      the current Stage object
    • exit

      public void exit()
      Exits the application by invoking the `whenExits` method and then calling the `exit` method on the `Applet` instance.
    • whenExits

      public void whenExits()
      This method is called when the window exits. Override this method to define custom behavior when the window is closed.