当我将鼠标悬停在屏幕上并让 Jframe 显示颜色本身时,如何让我的程序读取鼠标下的 rgb 值。RGB值。可能还有颜色的名称
所以当我的标题显示我需要一个像素颜色检测器
这是我到目前为止所拥有的,它打开了 jframe,但什么也没做
package project;
import java.awt.AWTException;
import java.awt.Color;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.PointerInfo;
import java.awt.Robot;
import javax.swing.JFrame;
public class Project {
private static int EXIT_ON_CLOSE;
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws AWTException {
//timer = new Timer(1000,this);
JFrame frame= new JFrame();
frame.setDefaultCloseOperation(EXIT_ON_CLOSE);
//JLabel lable = new JLabel();
//JScrollPane jsp = new JScrollPane(lable);
//frame.getContentPane().add(jsp);
frame. setSize(1000, 700);
frame.setVisible(true);
while(true) {
PointerInfo cursorLocation = MouseInfo.getPointerInfo();
Point position = cursorLocation.getLocation();
int x = (int)position.getX();
int y = (int)position.getY();
Robot bob = new Robot();
Color pixelColor = bob.getPixelColor(x, y);
int colorRed = pixelColor.getRed();
int colorGreen = pixelColor.getGreen();
int colorBlue = pixelColor.getBlue();
//System.out.print("Red " + colorRed + " Green " + colorGreen + " Blue " + colorBlue + "\n" );
frame.setName("Red " + colorRed + " Green " + colorGreen + " Blue " + colorBlue );
}
}
}