扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
import javax.swing.JFrame; MBb~,kEFTp
import javax.swing.JPanel; Ny MKb'
import javax.swing.JLabel; QN8^M
N=o~/%Wz|
import java.awt.Color; Ux5qDp3{D}
import java.awt.MouseInfo; E<@)u8
import java.awt.Point; |pzeFm
import java.awt.Toolkit; O%&PE[iP
import java.awt.Dimension; DSPD`m['
import java.awt.Robot; Y+`ns
import java.awt.Graphics; im[JpA
MXa@{M&
import java.awt.event.MouseMotionAdapter; 7/q:Or{
import java.awt.event.MouseEvent; @yWTFUb
uf<k6|-}fJ
public class PickColor extends JFrame implements Runnable 0},ac7l
{ x y!?
private Robot robot; KnLqUnkW)
private Color color = new Color(0, 0, 0); Q"m?8~;r
private Point point; f>J`-
private JPanel pane = new JPanel(); w52Y}A $
private JLabel label = new JLabel(); mb_I&43y
m`S@v"9j@
public PickColor(String title) j3@&/;W9>
{ ER9@NV!
super(title); hX!Z13L
.b-m)k/"
label.setHorizontalAlignment(JLabel.CENTER); W>[rM,ENv
getContentPane().add(pane, "Center"); $zlk@3=O
getContentPane().add(label, "South"); k1p 8}lP:
//getContentPane().addMouseMotionListener(new PickColorMouesMotionListener()); C/Fk oF*
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ucSjSjD7X
setSize(200,200); b#* d=&~%
display(); n.e\sT4(i
new Thread(this).start(); 5`#>^\p9
} kB> StW
public static void main(String[] args) UP}h:=,
{ G#pU,oL]1K
PickColor pc = new PickColor("PickColor"); LUKOxD8\
} K)XY 1
uGKK1jXz
public void display() _S@6+pgVi
{ jy 2o#M*9
Toolkit toolkit = Toolkit.getDefaultToolkit(); ry2p'hhk
Dimension dim = toolkit.getScreenSize(); |PP*.I(u
setLocation {?z e
( rzJS`Q0
(dim.width - getWidth()) / 2, nRZVX).q
(dim.height - getHeight()) / 2 mZw!={A8]
); &>d}1Y\9 i
setVisible(true); h&{!OcH
} xrcV~
d}dWO
// 对整个屏幕进行取色 qW5}8G3U
public void run() <Cz|Bp70
{ w(.EW/6?7
while(true) /\@QK_`m$
{ [j2B%eY3@"
try Y+7~8FHf
{ oYNa*
robot = new Robot(); V?Z3n;&
point = MouseInfo.getPointerInfo().getLocation(); &>\JPU(]
color = robot.getPixelColor(point.x, point.y); O' y,=~D7
pane.setBackground(color); 607knO? %g
label.setText("RGB(" + color.getRed() + ", " + color.getGreen() + ", " + color.getBlue() + ")"); ~q2S]90NXa
Thread.sleep(10); 9}=AyPW08`
} sE[]r;Bq[
catch(Exception e) /4Z kGH{\
{ T\) 8=~
e.printStackTrace(); "s")'Bt
} 6xPJ$3=
} } f NYBZh
} ?E3Mmqi<~e
} Fy,=$=,
'!3}G
class PickColorMouesMotionListener extends MouseMotionAdapter l9vuif+Xo查看本文来源 >
{ ]D["/tli
PickColorMouesMotionListener() uB|p_C'|
{ Ol JU:%2
} xjJf1 c
public void mouseMoved(MouseEvent e) c+7XZg+IW
{ ]qFIED
try Q)2-.bpe
{ d3ktv*Q|
robot = new Robot(); c;"bmZ>C
point = MouseInfo.getPointerInfo().getLocation(); 7I?c*$ i
color = robot.getPixelColor(point.x, point.y); 1%973W3'+x
pane.setBackground(color); j\4.R,P Y
label.setText("RGB(" + color.getRed() + ", " + color.getGreen() + ", " + color.getBlue() + ")"); !0Z fNq
Thread.sleep(10); xJX}`^r
} {qd(TGD{
catch(Exception ex) VW?QRe Y
{ # !!MQTk
ex.printStackTrace(); z4^q5t0;s2
} *Vi[vk)
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者