Home > Java > javaTutorial > body text

What are the Java operations that come with Matlab?

王林
Release: 2023-05-03 16:07:07
forward
1497 people have browsed it

1 Get the mouse position in the full screen

The upper left corner of the screen is the origin of the coordinates. It is recommended to use it in conjunction with a while loop or timer function to get the mouse position and mouse pixel color:

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

2 Get the current Clipboard content

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

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

3 Copy the content to the clipboard

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

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

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

4 Get the pixel color at the mouse position

Needs to be combined with the function to get the mouse position.

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()]
Copy after login

5 Get screenshot

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)
Copy after login

6 Create java window (and keep it always on top)

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)
Copy after login

7 Transparent window

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)
Copy after login

What are the Java operations that come with Matlab?

The above is the detailed content of What are the Java operations that come with Matlab?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!