屏幕取坐标程序-用于使用Robot类函数时的坐标确定
来源:互联网 发布:高并发解决方案java 编辑:程序博客网 时间:2024/04/30 21:56
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.image.BufferedImage;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.UIManager;
/**
*BY 黄金 ry0821119@buaa
*2009/06/10
*转载请注明作者,谢谢!
*/
public class MouseHelp extends JFrame implements ActionListener {
public static void main(String[] args) {
new MouseHelp();
}
private JButton start;
public MouseHelp() {
super("屏幕坐标确定");
try{
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
}catch(Exception exe){
exe.printStackTrace();
}
start = new JButton("开始");
start.addActionListener(this);
this.getContentPane().add(start);
this.setSize(200,80);
this.setVisible(true);
this.setResizable(false);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private void initGUI() {
JFrame frame = new JFrame();
frame.getContentPane().add(new Temp());
frame.setUndecorated(true);
frame.pack();
frame.setVisible(true);
frame.setSize(Toolkit.getDefaultToolkit().getScreenSize().width,Toolkit.getDefaultToolkit().getScreenSize().height);
frame.setAlwaysOnTop(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// com.sun.awt.AWTUtilities.setWindowOpacity(frame, 0.01f);
}
private class Temp extends JPanel implements MouseMotionListener{
private BufferedImage bi;
private int width,height;
private Point p=new Point();//当前鼠标移的地点
private Robot robot;
private Color color;
public Temp(){
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension screenSize = toolkit.getScreenSize();
Rectangle screenRect = new Rectangle(screenSize);
try{
robot = new Robot();
bi=robot.createScreenCapture(screenRect);
}catch(Exception e){
}
width=screenRect.width;
height=screenRect.height;
this.addMouseMotionListener(this);
}
public void paintComponent(Graphics g){
g.drawImage(bi,0,0,width,height,this);
g.setColor(Color.RED);
g.setFont(new Font("大号",Font.PLAIN,40));
int showX,showY;
if(p.x>width-500)
showX=p.x-515;
else
showX=p.x+15;
if(p.y<55)
showY=p.y+55;
else
showY=p.y-15;
String str = "("+p.x+","+p.y+") R:"+color.getRed()+",G:"+color.getGreen()+",B:"+color.getBlue();
g.drawString(str,showX,showY);
}
public void mouseMoved(MouseEvent e){
p=e.getPoint();
color=robot.getPixelColor(p.x, p.y);
repaint();
}
@Override
public void mouseDragged(MouseEvent e) {
// TODO Auto-generated method stub
}
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource() == start){
this.setExtendedState(JFrame.HIDE_ON_CLOSE);
initGUI();
}
}
}
/*
ps:
drawString 用法tip
graphics.setFont(font);
FontMetrics fm = graphics.getFontMetrics();
graphics.drawString("Hello!", 0, fm.getMaxAscent());
*/
- 屏幕取坐标程序-用于使用Robot类函数时的坐标确定
- 取屏幕工作区的坐标
- unity3d 屏幕坐标、鼠标位置、视口坐标和绘制GUI时使用的坐标
- 获取屏幕坐标,可用作Robot开发的工具
- android 根据点击屏幕坐标,确定点击的item位子
- c#控件-取屏幕坐标
- 取HTML元素坐标的函数
- 屏幕坐标,鼠标坐标,屏幕宽度等取值方式
- [CoffeeBot] 确定客户的坐标
- OpenGL 获取当前屏幕坐标对应的三维坐标,使用很简单glu库中的一个函数
- 地图坐标与屏幕坐标的转换
- 屏幕坐标与客户坐标的转换
- 屏幕坐标转客户区的坐标
- 世界坐标与屏幕坐标的转换
- 使用万能地图下载器进行坐标转换的时候如何确定平面坐标的选择
- 地理坐标、经纬度坐标与屏幕坐标的转换!
- Android 屏幕坐标/视图坐标/布局坐标三者间的关系
- 屏幕坐标、设备坐标以及逻辑坐标的区别
- java日记
- 让时间来证明
- C#开源资源大汇总
- jsp+mysql编码问题的一种解决方案
- delphi 从URL地址中获得文件名
- 屏幕取坐标程序-用于使用Robot类函数时的坐标确定
- 各位,看好你的手机SIM卡
- C++和JAVA传统中积极的一面
- php下载文件代码
- SQL基础:Oracle00-918:未明确定义列的错误
- C语言中的运算符 详细说明
- adr和ldr的区别--课堂问题笔记系列
- volatile在多线程中的应用
- x86访问数组元素(访问数据表)