The MouseEvent class in java programming

An event which indicates that a mouse action occurred in a component. A mouse action is considered to occur in a particular component if and only if the mouse cursor is over the unobscured part of the component's bounds when the action happens. Component bounds can be obscurred by the visible component's children or by a menu or by a top-level window. This event is used both for mouse events (click, enter, exit) and mouse motion events (moves and drags).


  MOUSE_CLICKED
The mouse clicked event type.
public static final int MOUSE_CLICKED
 
 
  MOUSE_DRAGGED
The mouse dragged event type.
public static final int MOUSE_DRAGGED
 
 
  MOUSE_ENTERED
The mouse entered event type.
public static final int MOUSE_ENTERED
 
 
  MOUSE_EXITED
The mouse exited event type.
public static final int MOUSE_EXITED
 
  MOUSE_FIRST
Marks the first integer id for the range of mouse event ids.
public static final int MOUSE_FIRST
 
  MOUSE_LAST
Marks the last integer id for the range of mouse event ids.
public static final int MOUSE_LAST
 
  MOUSE_MOVED
The mouse moved event type.
public static final int MOUSE_MOVED
 
  MOUSE_PRESSED
The mouse pressed event type.
public static final int MOUSE_PRESSED
 
  MOUSE_RELEASED
The mouse released event type.
public static final int MOUSE_RELEASED 
 
MOUSE_WHEEL
       The "mouse wheel" event. This is the only MouseWheelEvent. It occurs when a mouse equipped with a wheel has its wheel rotated.
      public static final int MOUSE_WHEEL

Important Classes and Interfaces

These classes and interfaces are defined in java.awt.event. The first three are the most commonly used.
MouseEventA MouseEvent object is passed to all mouse listeners. The most useful information in a MouseEvent is the x and y coordinates of the mouse cursor.
MouseListenerInterface for mouse presses, releases, clicks, enters, and exits.
MouseMotionListenerInterface for mouse moves and drags.
MouseInputListenerInterface combination of MouseListener and MouseMotionListener.

MouseAdapterClass useful for writing anonymous listener for mouse button presses, entering, ...
MouseMotionAdapterClass useful for writing anonymous listener for mouse movement.
Handling the mouse wheel.
MouseWheelEvent Object passed to mouseWheelMoved. Subclass of MouseEvent.
MouseWheelListenerInterface to handle wheel movements. Write mouseWheelMoved(MouseWheelEvent we)


Constructor Detail

public MouseEvent(Component source,int id,long when,int modifiers,int x,int y,
                   int clickCount,boolean popupTrigger,int button)
 
source - the Component that originated the event
id - the integer that identifies the event
when - a long int that gives the time the event occurred
modifiers - the modifier keys down during event (e.g. shift, ctr l, alt, meta) Either extended _DOWN_MASK or old _MASK modifiers should be used, but both models should not be mixed in one event. Use of the extended modifiers is preferred.
x - the horizontal x coordinate for the mouse location
y - the vertical y coordinate for the mouse location
clickCount - the number of mouse clicks associated with event
popupTrigger - a boolean, true if this event is a trigger for a popup menu
button - which of the mouse buttons has changed state. NOBUTTON, BUTTON1, BUTTON2 or BUTTON3.
 
 Method Detail

    getX
     public int getX()
Returns the x position of the event relative to the source component.
  getY
    public int getY()
Returns the y position of the event relative to the source component.
  getPoint
    public Point getPoint()
Returns the x,y position of the event relative to the source component.
  translatePoint
     public synchronized void translatePoint(int x,
                                         int y)
Translates the coordinate position of the event by x, y.
Parameters:
x - the x value added to the current x coordinate position
y - the y value added to the current y coordinate position
  getClickCount
      public int getClickCount()
Return the number of mouse clicks associated with this event.
  isPopupTrigger
      public boolean isPopupTrigger()
Returns whether or not this mouse event is the popup-menu trigger event for the platform.
  paramString
     public String paramString()
Overrides:
paramString in class ComponentEvent

0 comments:

Post a Comment

 

learn java programming Copyright © 2011-2012 | Powered by appsackel.org