JAVA中有没有直接获取鼠标在屏幕中的坐标.
在VC中直接就可以调用相应的API就可以了.
我想到的一个比较笨的方法就是,用VC做一个动态链接库,里面再封装这个功能函数?
真想到不有什么好办法,而且JAVA中调用DLL比较麻烦样的.

解决方案 »

  1.   

    如果只是拿坐标的话,我有个笨办法~
    建个全屏透明FRAME,加MouseMotionListener就行~
      

  2.   

    我记得在鼠标事件是有可以获得鼠标的坐标的,你可以看看MouseMotionListener这个接口吧,它里面有getX()和getY()
    这两个函数分别是获得横坐标和纵坐标的,我现在忘记怎么用了....
      

  3.   

    JAVA中有没有直接获取鼠标在屏幕中的坐标. 
    鼠标事件里面的 e.getX()和e.getY()是获得窗口的坐标。
    你这个屏幕也可以理解成一个窗体吗?
      

  4.   

    MouseEvent类可以吗?
    有以下方法
     Point getLocationOnScreen() 
              返回事件的绝对 x, y 坐标。 
     Point getPoint() 
              返回事件相对于源组件的 x, y 坐标。 
     int getX() 
              返回事件相对于源组件的水平 x 坐标。 
     int getXOnScreen() 
              返回事件的绝对水平 x 坐标。 
     int getY() 
              返回事件相对于源组件的垂直 y 坐标。 
     int getYOnScreen() 
              返回事件的绝对垂直 y 坐标。 
      

  5.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title> New Document </title>
    <meta name="Generator" content="EditPlus">
    <meta name="Author" content="">
    <meta name="Keywords" content="">
    <meta name="Description" content="">
    </head><body onmouseMove="getXY(event)">
    <script language="JavaScript">
    <!--
    function mouseX(evt) {
    if (evt.pageX) return evt.pageX;
    else if (evt.clientX)
       return evt.clientX + (document.documentElement.scrollLeft ?
       document.documentElement.scrollLeft :
       document.body.scrollLeft);
    else return null;
    }
    function mouseY(evt) {
    if (evt.pageY) return evt.pageY;
    else if (evt.clientY)
       return evt.clientY + (document.documentElement.scrollTop ?
       document.documentElement.scrollTop :
       document.body.scrollTop);
    else return null;
    }function getXY(event)
    {
        var e = event || window.event;
        var x = mouseX(e);
        var y = mouseY(e);
        document.getElementById("XY").innerHTML = "X:" + x + "<br />Y:" + y;
    }
    function getX(elementID)
    {
            var el = elementID
            return el.offsetLeft
       
    }
       
    function getY(elementID)
    {
            var el = elementID
            return el.offsetTop
       
    }function getElementPositionX(elemID)
    {
       var offsetTrail = document.getElementById(elemID);
       var offsetLeft = 0;   while(offsetTrail)
       {
          offsetLeft += offsetTrail.offsetLeft;
          offsetTrail = offsetTrail.offsetParent;
       }    if (navigator.userAgent.indexOf("Mac") != -1 &&
            typeof(document.body.leftMargin) != "undefined") {
            offsetLeft += document.body.leftMargin;
        }
       
        return offsetLeft;
    }function getElementPositionY(elemID)
    {
       var offsetTrail = document.getElementById(elemID);
       var offsetTop = 0;   while(offsetTrail)
       {
          offsetTop += offsetTrail.offsetTop;
          offsetTrail = offsetTrail.offsetParent;
       }    if (navigator.userAgent.indexOf("Mac") != -1 &&
            typeof(document.body.leftMargin) != "undefined") {
            offsetTop += document.body.topMargin;
        }
        return offsetTop;
    }
    function getElementPositionXY(elemID)
    {
       var offsetTrail = elemID;
       var offsetLeft = 24;
       var offsetTop =0;   while(offsetTrail)
       {
          offsetLeft += offsetTrail.offsetLeft;
          offsetTop += offsetTrail.offsetTop;
          offsetTrail = offsetTrail.offsetParent;
       }    if (navigator.userAgent.indexOf("Mac") != -1 &&
            typeof(document.body.leftMargin) != "undefined") {
            offsetLeft += document.body.leftMargin;
            offsetLeft += document.body.leftMargin;
        }
       document.getElementById("txt_left").innerText = offsetLeft;
       document.getElementById("txt_top").innerText = offsetTop;
        document.getElementById("divMsg").style.top = offsetTop + "px";
    }//-->
    </script>
    鼠标的绝对位置:<br />
    <span id="XY" style="color:red;"></span><br /><br />
    控件输入框txtPos的绝对位置:<br />
    X:<span id="txt_left" style="color:red;"></span><br />
    Y:<span id="txt_top" style="color:red;"></span><br />
    <input type="text" name="txtPos" id="txtPos" onfocus="getElementPositionXY(this)"/>
    <br /><br />
    <div id="divMsg" style="height:60px;width:100px;background-color:#cccccc"></div>
    </body>
    </html>