获取屏幕坐标,可用作Robot开发的工具

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);

 }


}



作为工具,把背景变为透明就完美了

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值