全屏取色代码public class Test2 extends JFrame implements Runnable { private Robot robot; private Color color = new Color(0, 0, 0); private Point point; private JPanel pane = new JPanel(); private JLabel label = new JLabel();
public Test2(String title) { super(title);
label.setHorizontalAlignment(JLabel.CENTER); getContentPane().add(pane, "Center"); getContentPane().add(label, "South"); //getContentPane().addMouseMotionListener(new PickColorMouesMotionListener()); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(200,200); display(); new Thread(this).start(); } public static void main(String[] args) { Test2 pc = new Test2("PickColor"); }
container.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
System.out.print("单击了鼠标按键,");
}
}
我的意思是取得JFrame以外的本地的RGB值 或者是鼠标事件! 就比如我启动一个JFrame 点击上面的获取RGB值
然后把鼠标移动在JFrame以外 来获取 不是JFrame上面的
{
private Robot robot;
private Color color = new Color(0, 0, 0);
private Point point;
private JPanel pane = new JPanel();
private JLabel label = new JLabel();
public Test2(String title)
{
super(title);
label.setHorizontalAlignment(JLabel.CENTER);
getContentPane().add(pane, "Center");
getContentPane().add(label, "South");
//getContentPane().addMouseMotionListener(new PickColorMouesMotionListener());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(200,200);
display();
new Thread(this).start();
}
public static void main(String[] args)
{
Test2 pc = new Test2("PickColor");
}
public void display()
{
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension dim = toolkit.getScreenSize();
setLocation
(
(dim.width - getWidth()) / 2,
(dim.height - getHeight()) / 2
);
setVisible(true);
}
// 对整个屏幕进行取色
public void run()
{
while(true)
{
try
{
robot = new Robot();
point = MouseInfo.getPointerInfo().getLocation();
color = robot.getPixelColor(point.x, point.y);
pane.setBackground(color);
label.setText("RGB(" + color.getRed() + ", " + color.getGreen() + ", " + color.getBlue() + ")");
Thread.sleep(10);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
}