目錄
1 取得滑鼠在全螢幕位置
2 取得當前剪切板內容
3 內容複製到剪切板
4 取得滑鼠處像素顏色
5 取得螢幕截圖
6 建立java視窗(並使其永遠在最上方)
7 透明視窗
首頁 Java java教程 Matlab中自備的Java操作有哪些

Matlab中自備的Java操作有哪些

May 03, 2023 pm 04:07 PM
java matlab

1 取得滑鼠在全螢幕位置

螢幕左上角為座標原點,取得滑鼠位置和取得滑鼠像素顏色建議和while循環或timer函數結合使用:

import java.awt.MouseInfo;
mousepoint=MouseInfo.getPointerInfo().getLocation();
mousepoint=[mousepoint.x,mousepoint.y]

2 取得當前剪切板內容

import java.awt.Toolkit
import java.awt.datatransfer.DataFlavor
clip=Toolkit.getDefaultToolkit().getSystemClipboard();

clipTf=clip.getContents([]);
clipContent=clipTf.getTransferData(DataFlavor.stringFlavor)

3 內容複製到剪切板

import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
clip=Toolkit.getDefaultToolkit().getSystemClipboard();

contentStr='欢迎关注slandarer随笔';

tText=StringSelection(contentStr);
clip.setContents(tText,[]);

4 取得滑鼠處像素顏色

需要和取得滑鼠位置的函數結合。

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 建立java視窗(並使其永遠在最上方)

import java.awt.Frame;
import java.awt.Point;

frame=Frame();

% 设置java窗口大小
frame.setSize(400,300)
% 设置java窗口位置
point=Point(300,200);
frame.setLocation(point)

% 使其永远在最上方
frame.setAlwaysOnTop(true);

% 设置窗口关闭回调(不设置的话java frame将无法关闭)
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();

% 设置java窗口大小
frame.setSize(400,200)
% 设置java窗口位置
point=Point(50,400);
frame.setLocation(point)

% 因为要依据数值设置按钮位置,因此setLayout(NULL)
frame.setLayout([]);

bt1=Button("点我试试");
bt2=Button("关闭窗口");

% 设置点击事件
hbt1=handle(bt1,'CallbackProperties');
set(hbt1,'MousePressedCallback',@(h,e)disp('欢迎关注公众号slandarer随笔'))

hbt2=handle(bt2,'CallbackProperties');
set(hbt2,'MousePressedCallback',@(h,e)frame.dispose())

% 设置按钮字体及字号
mf=Font('宋体',Font.BOLD,25);
bt1.setFont(mf)
bt2.setFont(mf)

% 设置按钮位置
bt1.setLocation(30,30);
bt1.setSize(140,140);
bt2.setLocation(220,30);
bt2.setSize(140,140);

% 添加按钮
frame.add(bt1);
frame.add(bt2);

% 取消边框并设置透明度
frame.setUndecorated(true);
frame.setOpacity(.7);

% 设置窗口关闭回调
hjWindow=handle(frame, 'CallbackProperties');
set(hjWindow, 'WindowClosingCallback', @(h,e)frame.dispose());

% 显示java窗口
frame.setVisible(true)

Matlab中自備的Java操作有哪些

以上是Matlab中自備的Java操作有哪些的詳細內容。更多資訊請關注PHP中文網其他相關文章!

本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱工具

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

熱門話題

Laravel 教程
1604
29
PHP教程
1510
276
用Docker將Java應用程序部署到Kubernetes 用Docker將Java應用程序部署到Kubernetes Aug 08, 2025 pm 02:45 PM

容器化Java應用:創建Dockerfile,使用基礎鏡像如eclipse-temurin:17-jre-alpine,複製JAR文件並定義啟動命令,通過dockerbuild構建鏡像並用dockerrun測試本地運行。 2.推送鏡像到容器註冊表:使用dockertag標記鏡像並推送到DockerHub等註冊表,需先登錄dockerlogin。 3.部署到Kubernetes:編寫deployment.yaml定義Deployment,設置副本數、容器鏡像和資源限制,編寫service.yaml創建

如何在Java中實現簡單的TCP客戶端? 如何在Java中實現簡單的TCP客戶端? Aug 08, 2025 pm 03:56 PM

Importjava.ioandjava.net.SocketforI/Oandsocketcommunication.2.CreateaSocketobjecttoconnecttotheserverusinghostnameandport.3.UsePrintWritertosenddataviaoutputstreamandBufferedReadertoreadserverresponsesfrominputstream.4.Usetry-with-resourcestoautomati

VS代碼快捷方式專注於Explorer面板 VS代碼快捷方式專注於Explorer面板 Aug 08, 2025 am 04:00 AM

VSCode中可通過快捷鍵快速切換面板與編輯區。要跳轉至左側資源管理器面板,使用Ctrl Shift E(Windows/Linux)或Cmd Shift E(Mac);返回編輯區可用Ctrl `或Esc或Ctrl 1~9。相比鼠標操作,鍵盤快捷鍵更高效且不打斷編碼節奏。其他技巧包括:Ctrl KCtrl E聚焦搜索框,F2重命名文件,Delete刪除文件,Enter打開文件,方向鍵展開/收起文件夾。

如何在Java中使用一個時循環 如何在Java中使用一個時循環 Aug 08, 2025 pm 04:04 PM

AwhileloopinJavarepeatedlyexecutescodeaslongastheconditionistrue;2.Initializeacontrolvariablebeforetheloop;3.Definetheloopconditionusingabooleanexpression;4.Updatethecontrolvariableinsidethelooptopreventinfinitelooping;5.Useexampleslikeprintingnumber

修復:Windows Update無法安裝 修復:Windows Update無法安裝 Aug 08, 2025 pm 04:16 PM

runthewindowsupdatetrubloubleshooterviaSettings>更新&安全> is esseShootsoAtomationfixCommonissues.2.ResetWindowSupDateComponentsByStoppingRealatedServices,RenamingTheSoftWaredWaredWaredSoftwaredSistribution andCatroot2Folders,intrestrestartingthertingthertingtherserviceSteStoceTocle

Java對象的序列化過程是什麼? Java對象的序列化過程是什麼? Aug 08, 2025 pm 04:03 PM

JavaserializationConvertSanObject'SstateIntoAbyTeSteAmForStorageorTransermission,andDeserializationReconstructstheObjectStheObjectFromThstream.1.toenableserialization,aclassMustimustimplementTheSerializableizableface.2.UseObjectObjectObjectObjectOutputputputputputtreamToserialializeanobectizeanobectementeabectenobexpent,savin

什麼是Java的哈希圖? 什麼是Java的哈希圖? Aug 11, 2025 pm 07:24 PM

ahashmapinjavaiSadattrastureturethatStoreskey-valuepairsforefficeFitedReval,插入和deletion.itusesthekey’shashcode()methodtodeTermInestorageLageLageAgeLageAgeAgeAgeAgeAneStorageAgeAndAllowSavereo(1)timecomplexityforget()

python numpy陣列示例 python numpy陣列示例 Aug 08, 2025 am 06:13 AM

NumPy數組的使用包括:1.創建數組(如從列表、全零、全一、範圍創建);2.形狀操作(reshape、轉置);3.向量化運算(加減乘除、廣播、數學函數);4.索引與切片(一維和二維操作);5.統計計算(最大值、最小值、均值、標準差、求和及軸向操作);這些操作高效且無需循環,適合大規模數值計算,最終掌握需多加練習。

See all articles