扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
import javax.swing.JFrame; S"M)7%ey<V`^u&:}a
import javax.swing.JPanel; LI$VE#zYq
import javax.swing.JLabel; KX.NDM&3P
y%c@DTmX
import java.awt.Color; 0XF39d#
import java.awt.MouseInfo; SF_bpio
import java.awt.Point; )}kzK@Q98
import java.awt.Toolkit; _8zO.c7
import java.awt.Dimension; YEy[VQ'd
import java.awt.Robot; 6F}IdYz{'4
import java.awt.Graphics; u/HMc#MF
S%]D5 /[
import java.awt.event.MouseMotionAdapter; H"h:a3tV
import java.awt.event.MouseEvent; HyQT-~V3K
W/'0>J9O
public class PickColor extends JFrame implements Runnable I>5ADIKp
{ #;hEkc.<K
private Robot robot; `*=$N*=)
private Color color = new Color(0, 0, 0); 6AOSn4
private Point point; dcA@gd^
private JPanel pane = new JPanel(); L3TX}qEq(
private JLabel label = new JLabel(); 5/p))(>zt
7tj(!M/v
public PickColor(String title) '4K*98GA
{ ^ERg0K9+v
super(title); RE%a]^ %[
4d VNb|q)
label.setHorizontalAlignment(JLabel.CENTER); ik "893 U
getContentPane().add(pane, "Center"); sW>Nyu
getContentPane().add(label, "South"); Sxb^D^s c
//getContentPane().addMouseMotionListener(new PickColorMouesMotionListener()); NW3x9Ket
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); pB76E)N (
setSize(200,200); 2oZ(V7!F}
display(); !x:`!Fy
new Thread(this).start(); 6! SJaXNmi
} <Ix(.-rC
public static void main(String[] args) )BCP s<IIR
{ m #!q2A
PickColor pc = new PickColor("PickColor"); *9~^Jf6
} B09PFtf
S(aV,u
public void display() ~9QBN%,'
{ : Rx</Rt
Toolkit toolkit = Toolkit.getDefaultToolkit(); Yu$uP E)j
Dimension dim = toolkit.getScreenSize(); 0-Ml=n?f
setLocation fFuyc
( t_w_@jZB
(dim.width - getWidth()) / 2, q7{lf$
(dim.height - getHeight()) / 2 tgu'+kU{
); JF5FuYVA
setVisible(true); a?}tg;'B
} A`,)PJWOY;
653pr|K
// 对整个屏幕进行取色 ZL((# e
public void run() pmi UHlY
{ qB>F9f'3
while(true) 7V/2b</
{ yS]~"@
try z/B?KRZ3
{ &QF7Z j
robot = new Robot(); b6zCg'2'
point = MouseInfo.getPointerInfo().getLocation(); -dP^ GA#+
color = robot.getPixelColor(point.x, point.y); up3.ogP4I
pane.setBackground(color); g8=#,Y'M
label.setText("RGB(" + color.getRed() + ", " + color.getGreen() + ", " + color.getBlue() + ")"); E?6=3~
Thread.sleep(10); j/ kFf
} xF| -g^ s
catch(Exception e) ^188DCYX
{ 5:Gk B .%b
e.printStackTrace(); i^ `.fBjw_
} onw}xaC3<
} WAQ[X%csl
} nGal)
} Aj"5)";6ts
!KWJ)(
class PickColorMouesMotionListener extends MouseMotionAdapter D7jg查看本文来源 >
{ F@I|iA0~Q
PickColorMouesMotionListener() Z"l: r!@#
{ :/V7L?{6I
} as<#3EJ.
public void mouseMoved(MouseEvent e) Q"8= nK
{ ">8607CvV
try 4ld!=TFX
{ Z b~>;L
robot = new Robot(); $yK|tQhH?
point = MouseInfo.getPointerInfo().getLocation(); q#Mq)r}
color = robot.getPixelColor(point.x, point.y); <9LFX'**
pane.setBackground(color); e,[RW $Y
label.setText("RGB(" + color.getRed() + ", " + color.getGreen() + ", " + color.getBlue() + ")"); Q$A[L-
Thread.sleep(10); 8 an9;~^
} S7|O~ho
catch(Exception ex) B`G =o:/
{ uG vFsv/s
ex.printStackTrace(); aL(Avp
} zJ*ip|
} ?,s,r P7N
} Xn,_!w-<;
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者