如何取得鼠标相对于屏幕的坐标,(包括鼠标在桌面上时)相当于winapi的getcursor?? sorry,应该是相当于getcursorpos 的winapi 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 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();就是得到鼠标相对屏幕的坐标。 sorry,我想我可能没有说明白,我要得到的是system-wide,不是application-wide的鼠标坐标,即鼠标在桌面上时,也能得到其坐标,此时根本就没有mouseevent。另外,我指的是pure java,不用jni的。谢谢。 哈哈,我用的就是纯java啊。如果想鼠标不在java应用上时得到坐标到是没有想过,这对java来说没有用啊!你在编什么应用啊?系统级的? samba的安装 canvas 在SplitPanel上拖动的问题 怎样socket才能一直占着一个tcp连接 我在一个方法中怎么样把另外的一个类打开呢? 关于我的一个计算器问题--请高手指点!!!--谢了 jbuilder8.0 在XP下的安装问题,请高手帮帮忙!!!!! 高分寻求eclipse资料 java读取excel文件的问题 哪里有Visual J++下载,急用 小弟以前专攻Delphi,想请教怎样制定一个好的学习java的计划? scjp(yy1) 有没有java打印的例子程序,请给两个!
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();
就是得到鼠标相对屏幕的坐标。
如果想鼠标不在java应用上时得到坐标到是没有想过,这对java来说没有用啊!你在编什么应用啊?系统级的?