sorry,应该是相当于getcursorpos 的winapi

解决方案 »

  1.   

    import java.awt.*;
    import java.awt.event.*;
    public class MyButton extends Button implements MouseListener{
      ToolTip tip1;
      public MyButton(String text) {
      super(text);
      addMouseListener(this);
      }
      public void mouseClicked(MouseEvent e){}
      public void mousePressed(MouseEvent e){}
      public void mouseReleased(MouseEvent e){}
      public void mouseEntered(MouseEvent e){
      tip1=new ToolTip((Frame)getParent(),"我是小铁针欢迎你的来到");
      tip1.setTipBackground(Color.cyan);
      tip1.setTipForeground(Color.red);
      Rectangle rectangle=this.getBounds();
      int x=this.getLocationOnScreen().x+e.getX();
      int y=this.getLocationOnScreen().y+e.getY();
      tip1.setLocation(x,y);
      //tip1.setLocation(e.getX(),e.getY());
      tip1.show();
      }
      public void mouseExited(MouseEvent e){
       tip1.hide();
      }

    源代码中的  int x=this.getLocationOnScreen().x+e.getX();
      int y=this.getLocationOnScreen().y+e.getY();
    就是得到鼠标相对屏幕的坐标。
      

  2.   

    sorry,我想我可能没有说明白,我要得到的是system-wide,不是application-wide的鼠标坐标,即鼠标在桌面上时,也能得到其坐标,此时根本就没有mouseevent。另外,我指的是pure java,不用jni的。谢谢。
      

  3.   

    哈哈,我用的就是纯java啊。
    如果想鼠标不在java应用上时得到坐标到是没有想过,这对java来说没有用啊!你在编什么应用啊?系统级的?