詳解Matlab中自帶的Java操作合集
1 獲取鼠標(biāo)在全屏位置
屏幕左上角為坐標(biāo)原點(diǎn),獲取鼠標(biāo)位置和獲取鼠標(biāo)像素顏色建議和while循環(huán)或者timer函數(shù)結(jié)合使用:
import java.awt.MouseInfo; mousepoint=MouseInfo.getPointerInfo().getLocation(); mousepoint=[mousepoint.x,mousepoint.y]
2 獲取當(dāng)前剪切板內(nèi)容
import java.awt.Toolkit import java.awt.datatransfer.DataFlavor clip=Toolkit.getDefaultToolkit().getSystemClipboard(); clipTf=clip.getContents([]); clipContent=clipTf.getTransferData(DataFlavor.stringFlavor)
3 內(nèi)容復(fù)制到剪切板
import java.awt.Toolkit; import java.awt.datatransfer.StringSelection; clip=Toolkit.getDefaultToolkit().getSystemClipboard(); contentStr='歡迎關(guān)注slandarer隨筆'; tText=StringSelection(contentStr); clip.setContents(tText,[]);?
4 獲取鼠標(biāo)處像素顏色
需要和獲取鼠標(biāo)位置的函數(shù)結(jié)合。
import java.awt.MouseInfo; import java.awt.Robot; robot=Robot(); mousepoint=MouseInfo.getPointerInfo().getLocation(); tempColor=robot.getPixelColor(mousepoint.x, mousepoint.y); RGBColor=[tempColor.getRed(),tempColor.getGreen(),tempColor.getBlue()]
5 獲取屏幕截圖
import java.awt.Robot; import java.awt.Rectangle; robot=Robot(); rectangle=Rectangle(); screensize=get(0,'screensize'); screensize=1.5*screensize; rectangle.x=0; rectangle.y=0; rectangle.width=screensize(3); rectangle.height=screensize(4); image=robot.createScreenCapture(rectangle); data=image.getData(); temp=zeros(screensize(3)*screensize(4)*3,1); temp=data.getPixels(0,0,screensize(3),screensize(4),temp); temp=uint8(temp); R=temp(1:3:end); G=temp(2:3:end); B=temp(3:3:end); R=reshape(R,[screensize(3),screensize(4)]); G=reshape(G,[screensize(3),screensize(4)]); B=reshape(B,[screensize(3),screensize(4)]); R=R';G=G';B=B'; ima=cat(3,R,G,B); imshow(ima)
6 創(chuàng)建java窗口(并使其永遠(yuǎn)在最上方)
import java.awt.Frame; import java.awt.Point; frame=Frame(); % 設(shè)置java窗口大小 frame.setSize(400,300) % 設(shè)置java窗口位置 point=Point(300,200); frame.setLocation(point) % 使其永遠(yuǎn)在最上方 frame.setAlwaysOnTop(true); % 設(shè)置窗口關(guān)閉回調(diào)(不設(shè)置的話java frame將無法關(guān)閉) hjWindow=handle(frame,'CallbackProperties'); set(hjWindow,'WindowClosingCallback',@(h,e)frame.dispose()); % 顯示java窗口 frame.setVisible(true)
7 透明窗口
import java.awt.Frame;
import java.awt.Point;
import java.awt.Button;
import java.awt.Font;
frame=Frame();
% 設(shè)置java窗口大小
frame.setSize(400,200)
% 設(shè)置java窗口位置
point=Point(50,400);
frame.setLocation(point)
% 因?yàn)橐罁?jù)數(shù)值設(shè)置按鈕位置,因此setLayout(NULL)
frame.setLayout([]);
bt1=Button("點(diǎn)我試試");
bt2=Button("關(guān)閉窗口");
% 設(shè)置點(diǎn)擊事件
hbt1=handle(bt1,'CallbackProperties');
set(hbt1,'MousePressedCallback',@(h,e)disp('歡迎關(guān)注公眾號(hào)slandarer隨筆'))
hbt2=handle(bt2,'CallbackProperties');
set(hbt2,'MousePressedCallback',@(h,e)frame.dispose())
% 設(shè)置按鈕字體及字號(hào)
mf=Font('宋體',Font.BOLD,25);
bt1.setFont(mf)
bt2.setFont(mf)
% 設(shè)置按鈕位置
bt1.setLocation(30,30);
bt1.setSize(140,140);
bt2.setLocation(220,30);
bt2.setSize(140,140);
% 添加按鈕
frame.add(bt1);
frame.add(bt2);
% 取消邊框并設(shè)置透明度
frame.setUndecorated(true);
frame.setOpacity(.7);
% 設(shè)置窗口關(guān)閉回調(diào)
hjWindow=handle(frame, 'CallbackProperties');
set(hjWindow, 'WindowClosingCallback', @(h,e)frame.dispose());
% 顯示java窗口
frame.setVisible(true)

以上就是詳解Matlab中自帶的Java操作合集的詳細(xì)內(nèi)容,更多關(guān)于Matlab自帶Java操作的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
數(shù)據(jù)結(jié)構(gòu)C語言鏈表的實(shí)現(xiàn)介紹
大家好,本篇文章主要講的是數(shù)據(jù)結(jié)構(gòu)C語言鏈表的實(shí)現(xiàn)介紹,感興趣的同學(xué)趕快來看一看吧,對(duì)你有幫助的話記得收藏一下2021-12-12
C++二維數(shù)組中數(shù)組元素存儲(chǔ)地址的計(jì)算疑問講解
今天小編就為大家分享一篇關(guān)于C++二維數(shù)組中數(shù)組元素存儲(chǔ)地址的計(jì)算疑問講解,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2019-02-02
C++ 構(gòu)造雙向鏈表的實(shí)現(xiàn)代碼
本篇文章是對(duì)C++中構(gòu)造雙向鏈表的實(shí)現(xiàn)代碼進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05
C++實(shí)現(xiàn)LeetCode數(shù)組練習(xí)題
這篇文章主要介紹了C++實(shí)現(xiàn)LeetCode的幾道數(shù)組練習(xí)題,本篇文章通過簡要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-08-08

