本文实例为大家分享了java实现人工智能化屏幕监控窗口的具体代码,供大家参考,具体内容如下
具体代码实现(含注释)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
public class main{ public static void main(string[] args) throws exception{ /* test code */ }
/** *用于实时监控屏幕的窗口 *@author chengxi *@param void *@return void */ public static void mvcontroll() throws exception{
/* 建立一个监控屏幕的窗口 */ jframe frame = new jframe("人工智能化屏幕监控系统") ; frame.setsize(600,600) ; frame.setvisible(true) ; /* 设置总是显示在顶部 */ frame.setalwaysontop(true) ; /* 获取默认的工具包 */ toolkit tk = toolkit.getdefaulttoolkit() ; /* 使用工具包获取屏幕的大小,这是创建工具包的唯一作用 */ dimension dm = tk.getscreensize() ; /* 创建图像的显示区域 */ jlabel imagelabel = new jlabel() ; frame.add(imagelabel) ; /* 创建一个机器人 */ robot robot = new robot() ; /* 持续监控屏幕 */ while(true) { /* 创建用于显示屏幕分享部分的区域,填入x/y/width/height rectangle rec = new rectangle(frame.getwidth() , 0 , (int)dm.getwidth() - frame.getwidth() , (int)dm.getheight()) ; /* 根据屏幕分享的当前分享图像创建一个图像对象 */ bufferedimage bufimg = robot.createscreencapture(rec)) ; /* 实时显示在图像显示区域中 */ imagelabel.seticon(new imageicon(bufimg)) ; } }
/** *打开指定的路径 public static void midopenqq(string path) throws exception{ desktop desktop = desktop.getdesktop() ; /* 打开指定的uri所指定的应用程序 */ desktop.open(new file(path)) ; /* 创建一个机器人 */ robot robot = new robot() ; /* 因为创建机器人需要时间,因此在后续操作之前需要进行延迟加载 */ robot.delay(2000) ; /* 使用robot的mousemove方法将鼠标的光标移动到指定的位置上,这里我设置的是qq界面的登录按钮上面 */ robot.mousemove(709,519) ; /* 定义鼠标事件:按下 */ robot.mousepress(inputevent.button1_down_mask) ; /* 定义鼠标事件:放开 */ robot.mouserelease(inputevent.button1_down_mask) ; /* 事件的延迟 */ robot.delay(300) ; }
/** *简单的打开path指定的路径所在的应用程序 *@author chengxi *@param string path *@return void */ public static void easyopenqq(string path) throws exception{ desktop desktop = desktop.getdesktop() ; /* 打开指定的文件 */ desktop.open(new file(path)) ; }
/** *打开uri指定的网址 *@author chengxi *@param string uri *@return void */ public static void openbrowse(string uri) throws exception{ /* 允许java程序使用在桌面上注册了的所有应用程序 */ desktop desktop = desktop.getdesktop() ; /* 使用默认的浏览器打开指定uri */ desktop.browse( new uri( "http://www.baidu.com" )) ; } |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
原文链接:https://blog.csdn.net/qq_27905183/article/details/53441368
查看更多关于java实现人工智能化屏幕监控窗口的详细内容...