What are the Java operations that come with Matlab?
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]
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)
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,[]);
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()]
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)
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)
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)
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Guide to Square Root in Java. Here we discuss how Square Root works in Java with example and its code implementation respectively.

Guide to Perfect Number in Java. Here we discuss the Definition, How to check Perfect number in Java?, examples with code implementation.

Guide to Random Number Generator in Java. Here we discuss Functions in Java with examples and two different Generators with ther examples.

Guide to Weka in Java. Here we discuss the Introduction, how to use weka java, the type of platform, and advantages with examples.

Guide to Smith Number in Java. Here we discuss the Definition, How to check smith number in Java? example with code implementation.

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is

Guide to TimeStamp to Date in Java. Here we also discuss the introduction and how to convert timestamp to date in java along with examples.
