jplay
Class Mouse

java.lang.Object
  extended by jplay.InputBase
      extended by jplay.Mouse
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.util.EventListener

public class Mouse
extends InputBase
implements java.awt.event.MouseMotionListener, java.awt.event.MouseListener

Class responsible for handling mouse actions.


Field Summary
static int BUTTON_LEFT
           
static int BUTTON_MIDDLE
           
static int BUTTON_RIGHT
           
 
Fields inherited from class jplay.InputBase
DETECT_EVERY_PRESS, DETECT_INITIAL_PRESS_ONLY
 
Constructor Summary
Mouse()
          Class constructor.
 
Method Summary
 java.awt.Point getPosition()
          Returns the position of the mouse on the screen.
 boolean isLeftButtonPressed()
          Returns true if the left button is pressed, otherwise false.
 boolean isMiddleButtonPressed()
          Returns true if the middle button is pressed, otherwise false.
 boolean isOverArea(int minX, int minY, int maxX, int maxY)
          Returns true if the mouse is over an area, otherwise, return false
 boolean isOverArea(java.awt.Point start, java.awt.Point end)
          Returns true if the mouse is over an object, otherwise, return false.
 boolean isOverObject(GameObject obj)
          Returns true if the mouse is over an object, otherwise, return false.
 boolean isRightButtonPressed()
          Returns true if the right button is pressed, otherwise false.
 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)
           
 void setBehavior(int numberBotton, int behavior)
          Sets the behavior of the mouse.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUTTON_LEFT

public static final int BUTTON_LEFT
See Also:
Constant Field Values

BUTTON_MIDDLE

public static final int BUTTON_MIDDLE
See Also:
Constant Field Values

BUTTON_RIGHT

public static final int BUTTON_RIGHT
See Also:
Constant Field Values
Constructor Detail

Mouse

public Mouse()
Class constructor. Creates an instance of the mouse positioned at (x=0, y=0). The behavior of the buttons (right, middle, left) is DECTECT_INITIAL_PRESS_ONLY.

Method Detail

getPosition

public java.awt.Point getPosition()
Returns the position of the mouse on the screen.

Returns:
Point

isLeftButtonPressed

public boolean isLeftButtonPressed()
Returns true if the left button is pressed, otherwise false.

Returns:
boolean

isMiddleButtonPressed

public boolean isMiddleButtonPressed()
Returns true if the middle button is pressed, otherwise false.

Returns:
boolean

isRightButtonPressed

public boolean isRightButtonPressed()
Returns true if the right button is pressed, otherwise false.

Returns:
boolean

setBehavior

public void setBehavior(int numberBotton,
                        int behavior)
Sets the behavior of the mouse.

Parameters:
numberBotton - it's represent the mouse button and can be BUTTON_LEFT, BUTTON_MIDDLE or BUTTON RIGHT.
behabior - it's can be DETECT_EVERY_PRESS or DETECT_INITIAL_PRESS_ONLY.

mouseClicked

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

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

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

mouseDragged

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

mouseMoved

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

isOverObject

public boolean isOverObject(GameObject obj)
Returns true if the mouse is over an object, otherwise, return false.

Parameters:
obj - any GameObject.
Returns:
boolean

isOverArea

public boolean isOverArea(java.awt.Point start,
                          java.awt.Point end)
Returns true if the mouse is over an object, otherwise, return false.

Parameters:
start - initial point of the area.
end - final point of the area.
Returns:
boolean

isOverArea

public boolean isOverArea(int minX,
                          int minY,
                          int maxX,
                          int maxY)
Returns true if the mouse is over an area, otherwise, return false

Returns:
boolean