framework
Class MouseState

java.lang.Object
  extended by framework.MouseState
All Implemented Interfaces:
MouseListener, MouseMotionListener, MouseWheelListener, EventListener

public class MouseState
extends Object
implements MouseListener, MouseMotionListener, MouseWheelListener

Listens to MouseEvent events to build a model of the state of the mouse.

Example usage:

 public class MouseDemo extends Game
 {
        private MouseState mouse = new MouseState();
        
        public void init ()
        {
                // use for detecting clicks
                addMouseListener(mouse);
                
                // updates mouse position constantly
                addMouseMotionListener(mouse);
                
                // use for detecting mouse wheel scrolling
                addMouseWheelListener(mouse);
        }
        
        public void update (int time)
        {
                mouse.update();
                
                Point2D p = mouse.getPosition();
                
                if (mouse.leftClicked())
                {
                        ...
                }
        }
 }
 


Constructor Summary
MouseState()
           
 
Method Summary
 boolean doubleClicked()
           
 int getDX()
           
 int getDY()
           
 Point getLastKnownPosition()
          Returns the last position the mouse was known to be at.
 Point getMovement()
           
 Point getPosition()
          Returns the mouse position.
 int getWheelRotation()
           
 int getX()
          Note: returns -1 if mouse is not over component
 int getY()
          Note: returns -1 if mouse is not over component
 boolean leftClicked()
           
 boolean leftDown()
           
 boolean middleClicked()
           
 boolean middleDown()
           
 void mouseClicked(MouseEvent e)
          Required for MouseListener interface.
 void mouseDragged(MouseEvent e)
          Required for MouseMotionListener interface.
 void mouseEntered(MouseEvent e)
          Required for MouseListener interface.
 void mouseExited(MouseEvent e)
          Required for MouseListener interface.
 void mouseMoved(MouseEvent e)
          Required for MouseMotionListener interface.
 void mousePressed(MouseEvent e)
          Required for MouseListener interface.
 void mouseReleased(MouseEvent e)
          Required for MouseListener interface.
 void mouseWheelMoved(MouseWheelEvent e)
          Required for MouseMotionListener interface.
 boolean rightClicked()
           
 boolean rightDown()
           
 void update()
          Process events which have been received since the last call to this method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MouseState

public MouseState()
Method Detail

update

public void update()
Process events which have been received since the last call to this method. This method should be called once per game loop.


leftClicked

public boolean leftClicked()

middleClicked

public boolean middleClicked()

rightClicked

public boolean rightClicked()

doubleClicked

public boolean doubleClicked()

leftDown

public boolean leftDown()

middleDown

public boolean middleDown()

rightDown

public boolean rightDown()

getPosition

public Point getPosition()
Returns the mouse position. If the mouse is not over the component, this will return null. If this is not the behaviour you want, use getLastKnownPosition().

This needs to be added as a MouseMotionListener listener to get meaningful results from this method.


getLastKnownPosition

public Point getLastKnownPosition()
Returns the last position the mouse was known to be at. This needs to be added as a MouseMotionListener listener to get meaningful results from this method.


getX

public int getX()
Note: returns -1 if mouse is not over component


getY

public int getY()
Note: returns -1 if mouse is not over component


getMovement

public Point getMovement()

getDX

public int getDX()

getDY

public int getDY()

getWheelRotation

public int getWheelRotation()

mouseClicked

public void mouseClicked(MouseEvent e)
Required for MouseListener interface.

Specified by:
mouseClicked in interface MouseListener

mouseEntered

public void mouseEntered(MouseEvent e)
Required for MouseListener interface.

Specified by:
mouseEntered in interface MouseListener

mouseExited

public void mouseExited(MouseEvent e)
Required for MouseListener interface.

Specified by:
mouseExited in interface MouseListener

mousePressed

public void mousePressed(MouseEvent e)
Required for MouseListener interface.

Specified by:
mousePressed in interface MouseListener

mouseReleased

public void mouseReleased(MouseEvent e)
Required for MouseListener interface.

Specified by:
mouseReleased in interface MouseListener

mouseDragged

public void mouseDragged(MouseEvent e)
Required for MouseMotionListener interface.

Specified by:
mouseDragged in interface MouseMotionListener

mouseMoved

public void mouseMoved(MouseEvent e)
Required for MouseMotionListener interface.

Specified by:
mouseMoved in interface MouseMotionListener

mouseWheelMoved

public void mouseWheelMoved(MouseWheelEvent e)
Required for MouseMotionListener interface.

Specified by:
mouseWheelMoved in interface MouseWheelListener