本文實例為大家分享了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