本文實例為大家分享了java實現人工智能化屏幕監控窗口的具體代碼,供大家參考,具體內容如下
具體代碼實現(含注釋)
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.companysz.com")) ; }
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VeVb武林網。
新聞熱點
疑難解答
圖片精選