获取屏幕坐标,可用作Robot开发的工具
2009-06-09 17:03
495 查看
import java.awt.Dimension;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.Robot;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.WindowConstants;
public class MouseHelp extends javax.swing.JPanel implements MouseMotionListener {
private JButton textButton;
Robot robot;
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.getContentPane().add(new MouseHelp());
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
public MouseHelp() {
super();
initGUI();
}
private void initGUI() {
try {
robot=new Robot();
addMouseMotionListener(this);
setPreferredSize(new Dimension(1024, 768));
/* this.setLayout(null);
{
textButton = new JButton();
this.add(textButton);
textButton.setText("/u8fd0 /u884c");
textButton.setBounds(136, 72, 127, 22);
textButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
robot.mouseMove(30,745);
try {
Thread.sleep(1000);
robot.mousePress(MouseEvent.BUTTON1_MASK);
robot.mouseRelease(MouseEvent.BUTTON1_MASK);
Thread.sleep(1000);
robot.mouseMove(150,481);
robot.mousePress(MouseEvent.BUTTON1_MASK);
robot.mouseRelease(MouseEvent.BUTTON1_MASK);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}});
}*/
} catch (Exception e) {
e.printStackTrace();
}
}
public void mouseDragged(MouseEvent e) {
}
public void mouseMoved(MouseEvent e) {
//从这里获取鼠标的全局坐标
Point mousepoint = MouseInfo.getPointerInfo().getLocation();
System.out.println(mousepoint.x+"/t"+mousepoint.y);
}
}
作为工具,把背景变为透明就完美了
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.Robot;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.WindowConstants;
public class MouseHelp extends javax.swing.JPanel implements MouseMotionListener {
private JButton textButton;
Robot robot;
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.getContentPane().add(new MouseHelp());
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
public MouseHelp() {
super();
initGUI();
}
private void initGUI() {
try {
robot=new Robot();
addMouseMotionListener(this);
setPreferredSize(new Dimension(1024, 768));
/* this.setLayout(null);
{
textButton = new JButton();
this.add(textButton);
textButton.setText("/u8fd0 /u884c");
textButton.setBounds(136, 72, 127, 22);
textButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
robot.mouseMove(30,745);
try {
Thread.sleep(1000);
robot.mousePress(MouseEvent.BUTTON1_MASK);
robot.mouseRelease(MouseEvent.BUTTON1_MASK);
Thread.sleep(1000);
robot.mouseMove(150,481);
robot.mousePress(MouseEvent.BUTTON1_MASK);
robot.mouseRelease(MouseEvent.BUTTON1_MASK);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}});
}*/
} catch (Exception e) {
e.printStackTrace();
}
}
public void mouseDragged(MouseEvent e) {
}
public void mouseMoved(MouseEvent e) {
//从这里获取鼠标的全局坐标
Point mousepoint = MouseInfo.getPointerInfo().getLocation();
System.out.println(mousepoint.x+"/t"+mousepoint.y);
}
}
作为工具,把背景变为透明就完美了
相关文章推荐
- 安卓开发获取用户点击屏幕坐标
- Swift - 获取屏幕点击坐标下所有对象(SpriteKit游戏开发)
- 利用JavaFx开发RIA桌面应用-获取屏幕四个角落的坐标
- Android 开发的常用工具类(一)——ScreenUtils 可用于获取屏幕宽高,截屏的工具类
- 安卓开发获取用户点击屏幕坐标
- iOS开发- 根据表格点击tableviewCell获取在当前屏幕中的坐标值
- C#软件开发实例.私人订制自己的屏幕截图工具——放大镜的功能代码优化
- c#中获取屏幕上鼠标的坐标
- 获取控件在屏幕中的坐标
- IOS开发之——获取屏幕的尺寸及各模拟器代表的型号
- IOS开发之——获取屏幕的尺寸及各模拟器代表的型号
- 获取任意View在屏幕上的坐标
- iOS开发---通过坐标位置获取对应的UITableViewCell
- Android开发-触屏事件的获取和触摸屏幕位置
- l转 Js 获取屏幕坐标值
- 获取tcl开发工具
- 双屏,多屏情况下,获取屏幕的坐标
- js获取窗口相对于屏幕左边和上边的位置坐标
- Android开发中MotionEvent坐标获取方法分析
- Android开发中获取手机屏幕的大小