Class AWTInput

  • All Implemented Interfaces:
    java.awt.event.KeyListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.util.EventListener, InputDevice, Updatable

    public class AWTInput
    extends java.lang.Object
    implements InputDevice, Updatable, java.awt.event.KeyListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener
    Input device that uses AWT to capture mouse and keyboard events.
    • Constructor Summary

      Constructors 
      Constructor Description
      AWTInput​(Canvas canvas)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.util.List<Point2D> getPointers()
      Returns the current locations of all currently active pointers.
      boolean isKeyboardAvailable()
      Returns true if the current device has a hardware keyboard.
      boolean isKeyPressed​(int keycode)  
      boolean isKeyPressed​(KeyCode keyCode)
      Returns true if the key with the specified key code was pressed during the current frame.
      boolean isKeyReleased​(int keycode)  
      boolean isKeyReleased​(KeyCode keyCode)
      Returns true if the key with the specified key code was released during the current frame.
      boolean isPointerPressed​(Rect area)
      Returns true if any of the currently active pointers have been pressed and located within the specified area during the current frame.
      boolean isPointerReleased​(Rect area)
      Returns true if any of the currently active pointers were released and located within the specified area during the current frame.
      boolean isTouchAvailable()
      Returns if the current device supports touch input.
      void keyPressed​(java.awt.event.KeyEvent e)  
      void keyReleased​(java.awt.event.KeyEvent e)  
      void keyTyped​(java.awt.event.KeyEvent e)  
      void mouseClicked​(java.awt.event.MouseEvent e)  
      void mouseDragged​(java.awt.event.MouseEvent e)  
      void mouseEntered​(java.awt.event.MouseEvent e)  
      void mouseExited​(java.awt.event.MouseEvent e)  
      void mouseMoved​(java.awt.event.MouseEvent e)  
      void mousePressed​(java.awt.event.MouseEvent e)  
      void mouseReleased​(java.awt.event.MouseEvent e)  
      java.lang.String requestTextInput​(java.lang.String labelText, java.lang.String initialValue)
      Shows a dialog window requesting the user to enter text.
      void update​(float deltaTime)
      Copies all events that have been received during the last frame to this class' internal state.
      • Methods inherited from class java.lang.Object

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

      • AWTInput

        public AWTInput​(Canvas canvas)
    • Method Detail

      • update

        public void update​(float deltaTime)
        Copies all events that have been received during the last frame to this class' internal state. This method must be called every frame.
        Specified by:
        update in interface Updatable
        Parameters:
        deltaTime - Elapsed time since the last frame, in seconds.
      • keyPressed

        public void keyPressed​(java.awt.event.KeyEvent e)
        Specified by:
        keyPressed in interface java.awt.event.KeyListener
      • keyReleased

        public void keyReleased​(java.awt.event.KeyEvent e)
        Specified by:
        keyReleased in interface java.awt.event.KeyListener
      • keyTyped

        public void keyTyped​(java.awt.event.KeyEvent e)
        Specified by:
        keyTyped in interface java.awt.event.KeyListener
      • mousePressed

        public void mousePressed​(java.awt.event.MouseEvent e)
        Specified by:
        mousePressed in interface java.awt.event.MouseListener
      • mouseReleased

        public void mouseReleased​(java.awt.event.MouseEvent e)
        Specified by:
        mouseReleased in interface java.awt.event.MouseListener
      • mouseClicked

        public void mouseClicked​(java.awt.event.MouseEvent e)
        Specified by:
        mouseClicked in interface java.awt.event.MouseListener
      • mouseEntered

        public void mouseEntered​(java.awt.event.MouseEvent e)
        Specified by:
        mouseEntered in interface java.awt.event.MouseListener
      • mouseExited

        public void mouseExited​(java.awt.event.MouseEvent e)
        Specified by:
        mouseExited in interface java.awt.event.MouseListener
      • mouseMoved

        public void mouseMoved​(java.awt.event.MouseEvent e)
        Specified by:
        mouseMoved in interface java.awt.event.MouseMotionListener
      • mouseDragged

        public void mouseDragged​(java.awt.event.MouseEvent e)
        Specified by:
        mouseDragged in interface java.awt.event.MouseMotionListener
      • getPointers

        public java.util.List<Point2D> getPointers()
        Description copied from interface: InputDevice
        Returns the current locations of all currently active pointers. When using a mouse, this will always return a list with a single element. For touch controls, the list could also have multiple elements (during multi-touch gestures) or the list could be empty (unlike mouse events, touch coordinates are only available during the event itself).
        Specified by:
        getPointers in interface InputDevice
      • isPointerPressed

        public boolean isPointerPressed​(Rect area)
        Description copied from interface: InputDevice
        Returns true if any of the currently active pointers have been pressed and located within the specified area during the current frame.
        Specified by:
        isPointerPressed in interface InputDevice
      • isPointerReleased

        public boolean isPointerReleased​(Rect area)
        Description copied from interface: InputDevice
        Returns true if any of the currently active pointers were released and located within the specified area during the current frame.
        Specified by:
        isPointerReleased in interface InputDevice
      • isKeyboardAvailable

        public boolean isKeyboardAvailable()
        Description copied from interface: InputDevice
        Returns true if the current device has a hardware keyboard.
        Specified by:
        isKeyboardAvailable in interface InputDevice
      • isKeyPressed

        public boolean isKeyPressed​(KeyCode keyCode)
        Description copied from interface: InputDevice
        Returns true if the key with the specified key code was pressed during the current frame.
        Specified by:
        isKeyPressed in interface InputDevice
      • isKeyPressed

        public boolean isKeyPressed​(int keycode)
      • isKeyReleased

        public boolean isKeyReleased​(KeyCode keyCode)
        Description copied from interface: InputDevice
        Returns true if the key with the specified key code was released during the current frame.
        Specified by:
        isKeyReleased in interface InputDevice
      • isKeyReleased

        public boolean isKeyReleased​(int keycode)
      • requestTextInput

        public java.lang.String requestTextInput​(java.lang.String labelText,
                                                 java.lang.String initialValue)
        Description copied from interface: InputDevice
        Shows a dialog window requesting the user to enter text. This method exists only because text fields, unlike other input elements such as buttons, cannot be emulated by the renderer without losing common functionality such as copy/paste. Text input must therefore be delegated to the platform so that a native text field can be used.
        Specified by:
        requestTextInput in interface InputDevice