java实现获取鼠标在屏幕上的坐标
来源:互联网 发布:睡觉流口水 知乎 编辑:程序博客网 时间:2024/05/16 05:13
本篇博客其实没什么难度可言,在这里分享给大家,是因为有时候我们需要这个工具,java作为跨平台语言的优势在这个软件就可以体现出来,不需修改就可以在windows、mac、linux上使用这个软件。
这个小工具主要是使用MouseInfo类实时获取鼠标的信息,然后再JDialog上显示出来。
代码如下:
import java.awt.BorderLayout;import java.awt.FlowLayout;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JFrame;import javax.swing.JPanel;import javax.swing.border.EmptyBorder;import javax.swing.JLabel;import java.awt.Font;import java.awt.Point;import java.util.Timer;import java.util.TimerTask;import java.awt.Color;public class MouseInfo extends JFrame { private final JPanel contentPanel = new JPanel(); JLabel value_x = null; JLabel value_y = null; /** * Launch the application. */ public static void main(String[] args) { try { MouseInfo info_frame = new MouseInfo(); info_frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); info_frame.setVisible(true); info_frame.setAlwaysOnTop(true); Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { Point point = java.awt.MouseInfo.getPointerInfo().getLocation(); // System.out.println("Location:x=" + point.x + ", y=" + // point.y); info_frame.value_x.setText("" + point.x); info_frame.value_y.setText("" + point.y); } }, 100, 100); } catch (Exception e) { e.printStackTrace(); } } /** * Create the dialog. */ public MouseInfo() { setTitle("\u9F20\u6807\u5750\u6807\u83B7\u53D6\u5668"); setBounds(100, 100, 217, 156); getContentPane().setLayout(new BorderLayout()); contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); getContentPane().add(contentPanel, BorderLayout.CENTER); contentPanel.setLayout(null); JLabel lblx = new JLabel("\u5750\u6807x:"); lblx.setFont(new Font("宋体", Font.PLAIN, 15)); lblx.setBounds(22, 27, 66, 31); contentPanel.add(lblx); JLabel lbly = new JLabel("\u5750\u6807y:"); lbly.setFont(new Font("宋体", Font.PLAIN, 15)); lbly.setBounds(22, 68, 66, 31); contentPanel.add(lbly); value_x = new JLabel("0"); value_x.setForeground(Color.BLUE); value_x.setFont(new Font("宋体", Font.PLAIN, 20)); value_x.setBounds(82, 27, 66, 31); contentPanel.add(value_x); value_y = new JLabel("0"); value_y.setForeground(Color.BLUE); value_y.setFont(new Font("宋体", Font.PLAIN, 20)); value_y.setBounds(82, 68, 66, 31); contentPanel.add(value_y); }}
附上工具下载链接:http://download.csdn.net/detail/code_better/9808316
0 0
- java实现获取鼠标在屏幕上的坐标
- 获取鼠标在屏幕上的坐标和颜色值(RGB)
- c#中获取屏幕上鼠标的坐标
- 获取网页上的屏幕信息和鼠标坐标
- 获取组件在屏幕上的坐标位置
- Unity3D 获取控件四个角在屏幕上的坐标
- MFC获取控件在屏幕上的绝对坐标
- android view获取在屏幕上的绝对坐标
- 获取任意View在屏幕上的坐标
- java获取屏幕上某坐标点的颜色
- html获取鼠标在页面的坐标以及在canvas上的坐标
- 鼠标屏幕坐标获取器
- 获取cancvs上鼠标的坐标信息
- 跟踪鼠标在窗口上的坐标
- 获取View控件在屏幕的坐标
- Winfrom 获取控件在屏幕的坐标
- VC 获取鼠标 点击时的屏幕坐标
- 获取鼠标的坐标
- 远程DNS缓存攻击__山东大学网络攻防实验三
- NFS /etc/exports 設定檔的語法與參數
- maven私服nexus配置
- uboot分析一
- VMware下基于RHEL_6.0虚拟机的samba服务器安装
- java实现获取鼠标在屏幕上的坐标
- blog书写专栏,how
- Linux常用文件操作命令
- logger.isDebugEnabled()的作用
- zStack 扩展开发流程-zstack-java部分
- python-正则表达式 匹配多个字符串的语法规则
- BOOST 线程完全攻略 - 基础篇 .
- oracle一些常用函数用法
- Android四大动画详解