扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
import javax.swing.JFrame; tc)baXuok;y Q8
import javax.swing.JPanel; n >$]2VsQ
import javax.swing.JLabel; L+)LJ <!
}<s"9z4Q
import java.awt.Color; &U8c"5
import java.awt.MouseInfo; _x ]^A; 5z
import java.awt.Point; r"|/gp#h'
import java.awt.Toolkit; 9eN1B{Ch($
import java.awt.Dimension; B`\7]D
import java.awt.Robot; ?t7Ma,IUA
import java.awt.Graphics; iJL;[O,F
Z;M:&7-
import java.awt.event.MouseMotionAdapter; 5j8w/.~
import java.awt.event.MouseEvent; CU .,
IN%xj(zr
public class PickColor extends JFrame implements Runnable yYc~CHyRn
{ ?E`KRcm$ r
private Robot robot; c% F+vz1R=
private Color color = new Color(0, 0, 0); H$UQ/`
private Point point; C 0s2z=)My
private JPanel pane = new JPanel(); lk7S-.G
private JLabel label = new JLabel(); 8C|}67'
>L\ 's
public PickColor(String title) 50ays0xBI
{ E Y |B(G
super(title); 1(2_#Aq
=79Ylx]~T
label.setHorizontalAlignment(JLabel.CENTER); ^9fai1@J-
getContentPane().add(pane, "Center"); $|~2Nk1[
getContentPane().add(label, "South"); F'rcvXg /
//getContentPane().addMouseMotionListener(new PickColorMouesMotionListener()); /U;M
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); LV&[HL
setSize(200,200); ]?~,.,#
display(); C/lHuw
new Thread(this).start(); P=7}`X/a|
} MJ="5ZA55
public static void main(String[] args) q@v12PX,
{ Kj&L
PickColor pc = new PickColor("PickColor"); G2MB:Q6
} [@] `SQ.m
W>Qa/SAu
public void display() ZxnQ[osH
{ o.rulA+V
Toolkit toolkit = Toolkit.getDefaultToolkit(); .xHR1 Z<h
Dimension dim = toolkit.getScreenSize(); 6:0R.p+'
setLocation 0qjgY
( }`ErRg"-^
(dim.width - getWidth()) / 2, 9:+ o`W e
(dim.height - getHeight()) / 2 %/_?XzW
); t5T`&~Tw
setVisible(true); 7` 0Nqk
} A@0Is4B
hmhiW82
// 对整个屏幕进行取色 v,-kVHf g
public void run() *N)(Xvc;1G
{ =!Xt9c+a
while(true) +yJ}$)
{ 2VGrWSK
try $@, bh
{ iAeZAc1e4
robot = new Robot(); 8OQ{#dd
point = MouseInfo.getPointerInfo().getLocation(); M@in~5
color = robot.getPixelColor(point.x, point.y); 9ph<FZc
pane.setBackground(color); yj[@E"<l-
label.setText("RGB(" + color.getRed() + ", " + color.getGreen() + ", " + color.getBlue() + ")"); nNH8odAt
Thread.sleep(10); do>ySed
} L8t< F&
catch(Exception e) q2q4sVir
{ a )1|}'
e.printStackTrace(); ;6>%|aB9
} r$Q4AnnB7
} Dd9` 5(4T
} C3`yOku%
} t-"(^Ph
19=26{M l
class PickColorMouesMotionListener extends MouseMotionAdapter +Xqc 1m查看本文来源 l>
{ 1hcoyWD
PickColorMouesMotionListener() kru& ^q
{ Tux4S3]J
} Q!q D/`(0
public void mouseMoved(MouseEvent e) ?as4 J@ [I
{ Z)j@(xu
try `}]R73-ex
{ 5bzsnJh
robot = new Robot(); 6WAtTitx#
point = MouseInfo.getPointerInfo().getLocation(); QvR@Hr[fN
color = robot.getPixelColor(point.x, point.y); EF&^/M
pane.setBackground(color); Du77UN'0
label.setText("RGB(" + color.getRed() + ", " + color.getGreen() + ", " + color.getBlue() + ")"); .W,26 /
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者