Class Mouse


  • public final class Mouse
    extends java.lang.Object
    Class representing the system mouse.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Mouse.Button
      Enumeration representing mouse buttons.
      static class  Mouse.ScrollType
      Enumeration defining supported scroll types.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void capture​(Component capturerComponent)
      "Captures" the mouse, causing all mouse input to be delegated to the given component rather than propagating down the component hierarchy.
      static int getButtonCount()  
      static int getButtons()  
      static Component getCapturer()
      Returns the mouse capturer.
      static Cursor getCursor()  
      static boolean isPressed​(Mouse.Button button)
      Tests the pressed state of a mouse button.
      static void release()
      Releases mouse capture, causing mouse input to resume propagation down the component hierarchy.
      protected static void setButtons​(int pressedButtons)
      Set the current bitmask of the buttons that are pressed (only callable from this package).
      static void setCursor​(Component component)
      Sets the cursor based on a given component.
      static void setCursor​(Cursor cursor)
      Sets the cursor to an explicit value.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getButtons

        public static int getButtons()
        Returns:
        A bitfield representing the mouse buttons that are currently pressed.
      • setButtons

        protected static void setButtons​(int pressedButtons)
        Set the current bitmask of the buttons that are pressed (only callable from this package).
        Parameters:
        pressedButtons - The current button bitmask.
        See Also:
        Mouse.Button.getButtons(int)
      • isPressed

        public static boolean isPressed​(Mouse.Button button)
        Tests the pressed state of a mouse button.
        Parameters:
        button - The button to test.
        Returns:
        true if the button is pressed; false, otherwise.
      • getButtonCount

        public static int getButtonCount()
        Returns:
        The number of mouse buttons.
      • capture

        public static void capture​(Component capturerComponent)
        "Captures" the mouse, causing all mouse input to be delegated to the given component rather than propagating down the component hierarchy.
        Parameters:
        capturerComponent - The component that wants to capture the mouse. The mouse pointer must currently be over the component.
      • release

        public static void release()
        Releases mouse capture, causing mouse input to resume propagation down the component hierarchy.
      • getCapturer

        public static Component getCapturer()
        Returns the mouse capturer.
        Returns:
        The component that has captured the mouse, or null if the mouse is not currently captured.
      • getCursor

        public static Cursor getCursor()
        Returns:
        The current cursor.
        Throws:
        java.lang.IllegalStateException - If the mouse is not currently captured.
      • setCursor

        public static void setCursor​(Cursor cursor)
        Sets the cursor to an explicit value.
        Parameters:
        cursor - The new mouse cursor value.
        Throws:
        java.lang.IllegalArgumentException - if the cursor value is null.
        java.lang.IllegalStateException - If the mouse is not currently captured.
      • setCursor

        public static void setCursor​(Component component)
        Sets the cursor based on a given component.
        Parameters:
        component - The component used to set the cursor.
        Throws:
        java.lang.IllegalArgumentException - if the component is null, or if the component is not currently visible.