java.awt.event 
Class MouseEvent
java.lang.Object
  |
  +-java.util.EventObject
        |
        +-java.awt.AWTEvent
              |
              +-java.awt.event.ComponentEvent
                    |
                    +-java.awt.event.InputEvent
                          |
                          +-java.awt.event.MouseEventgetPoint
public Point getPoint()Returns the x,y position of the event relative to the source component.
Returns:a Point object containing the x and y coordinates 
         relative to the source component

解决方案 »

  1.   

    to skyyoung(路人甲) :   我的本意是不添加mouse listener 或 mouseAdapter来实现.
    如果使用你说的方法是无法实现这个要求的.
      

  2.   

    我的创意:I don't know,but I want to know.
      

  3.   

    应该可以的,所有的组件基本上都继承于java.awt.component,在这个类中,processEvent方法是专门用来传递各种awtEvent的事件的,如果你重载这个方法的话,每当有事件产生,这个方法就会被call,这是你就可以通过参数得到。方法如下。不过兄弟你这样何苦来的呢?protected void processEvent(AWTEvent e) {
            if (e instanceof FocusEvent) {
                processFocusEvent((FocusEvent)e);        } else if (e instanceof MouseEvent) {
                switch(e.getID()) {
                  case MouseEvent.MOUSE_PRESSED:
                  case MouseEvent.MOUSE_RELEASED:
                  case MouseEvent.MOUSE_CLICKED:
                  case MouseEvent.MOUSE_ENTERED:
                  case MouseEvent.MOUSE_EXITED:
                    processMouseEvent((MouseEvent)e);
                    break;
                  case MouseEvent.MOUSE_MOVED:
                  case MouseEvent.MOUSE_DRAGGED:
                    processMouseMotionEvent((MouseEvent)e);
                    break;
                }        } else if (e instanceof KeyEvent) {
                processKeyEvent((KeyEvent)e);        } else if (e instanceof ComponentEvent) {
                processComponentEvent((ComponentEvent)e);
            } else if (e instanceof InputMethodEvent) {
                processInputMethodEvent((InputMethodEvent)e);
            } else if (e instanceof HierarchyEvent) {
        switch (e.getID()) {
          case HierarchyEvent.HIERARCHY_CHANGED:
    processHierarchyEvent((HierarchyEvent)e);
    break;
          case HierarchyEvent.ANCESTOR_MOVED:
          case HierarchyEvent.ANCESTOR_RESIZED:
    processHierarchyBoundsEvent((HierarchyEvent)e);
    break;
        }
    }
        }
      

  4.   

     private void MouseMove(java.awt.event.MouseEvent evt) 
        {
            X = evt.getX();
            Y = evt.getY();
        }