站长资讯平台首页站长百科网络编程http://blog.csdn.net/mq612"
*/
public class Test extends JFrame {
private static final long serialVersionUID = -267804510087895906L;
private JButton button = null;
private JLabel imgLabel = null;
public Test() {
button = new JButton("模拟屏幕(点右键退出)");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
new ScreenWindow(imgLabel);
} catch (Exception e1) {
JOptionPane.showConfirmDialog(null, "出现意外错误!", "系统提示", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
}
}
});
JPanel pane = new JPanel();
pane.setBackground(Color.WHITE);
imgLabel = new JLabel();
pane.add(imgLabel);
JScrollPane spane = new JScrollPane(pane);
this.getContentPane().add(button, BorderLayout.NORTH);
this.getContentPane().add(spane);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(300, 200);
this.setLocationRelativeTo(null);
this.setVisible(true);
}
public static void main(String[] args) {
new Test();
}
}
class ScreenWindow extends JFrame {
private static final long serialVersionUID = -3758062802950480258L;
private boolean isDrag = false;
private int x = 0;
private int y = 0;
private int xEnd = 0;
private int yEnd = 0;
public ScreenWindow(final JLabel imgLabel) throws AWTException, InterruptedException {
Dimension screenDims = Toolkit.getDefaultToolkit().getScreenSize();
JLabel label = new JLabel(new ImageIcon(ScreenImage.getScreenImage(0, 0, screenDims.width, screenDims.height)));
label.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
label.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON3) {
dispose();
}
}
public void mousePressed(MouseEvent e) {
x = e.getX();
y = e.getY();
}
public void mouseReleased(MouseEvent e) {
if (isDrag) {
xEnd = e.getX();
yEnd = e.getY();
if(x > xEnd){
int temp = x;
x = xEnd;
xEnd = temp;
}
if(y > yEnd){
int temp = y;
y = yEnd;
yEnd = temp;
}
try {
imgLabel.setIcon(new ImageIcon(ScreenImage.getScreenImage(x, y, xEnd - x, yEnd - y)));
} catch (Exception ex) {
JOptionPane.showConfirmDialog(null, "出现意外错误!", "系统提示", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
}
dispose();
}
}
});
label.addMouseMotionListener(new MouseMotionListener() {
public void mouseDragged(MouseEvent e) {
if(!isDrag)
isDrag = true;
}
public void mouseMoved(MouseEvent e) {
/** 拖动过程的虚线选取框需自己实现 */
}
});
this.setUndecorated(true);
this.getContentPane().add(label);
this.setSize(screenDims.width, screenDims.height);
this.setVisible(true);
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
}
}
class ScreenImage {
public static Image getScreenImage(int x, int y, int w, int h) throws AWTException, InterruptedException {
Robot robot = new Robot();
Image screen = robot.createScreenCapture(new Rectangle(x, y, w, h)).getScaledInstance(w, h, Image.SCALE_SMOOTH);
MediaTracker tracker = new MediaTracker(new Label());
tracker.addImage(screen, 1);
tracker.waitForID(0);
return screen;
}
}
标签:
ispseoPHP获取用户的真实 IP快速排序的算法php实现uCharts 1.9.3 发布,高性能跨平台Grafana 6.4.2 发布,系统指标监控Rancher 2.3 发布,支持 Windows 容Calibre 4.1.0 发布,开源电子书管Cyberduck 7.1.1?发布,FTP文件传输SEO的用户互动:论在线评论内容的重3个被忽视策略帮你提升电商网站流量如何找到并改进那些效果不佳的入口详细说说目标关键词说说那些能够在三个月做到10万IP的流量为王是SEO思维的毒药透析网站跳出率:页面质量很重要!百度零位置排名,如何利用其快速获干货:4大标题优化技巧原理引爆自然网站百度快照时间不更新或倒退怎么域名恶意指向含义、原理、后果、测百度抛彩蛋:移动搜索开启傻瓜模式中联数据与乌兰察布市战略合作 亚信云主机和VPS的区别2019年中国物联网网络连接数将迎来企业邮箱界的“高材生”,强力解锁虚拟主机哪个好域名成了搜索引擎的催化剂揭秘“百度加大清理新闻源力度”SSD固态硬盘云主机上线读写速度100网站seo网络网站优化安全百度互联网服务器云计算媒体大数据代码外链建设搜索搜索优化数据淘宝搜索引擎百度百通信博数据库网站推广金融排名Google推广谷歌网站排名关键词优化网络安全运维经验IT技术分享运维随笔录鲜花东郊到家往约到家
智能索引记录
-
2026-04-28 09:31:47
综合导航
成功
标题:逆天小魔妃:帝君,咬一口!_一方素笺_第91章 差一点就成失足少女了!_全本小说网
简介:全本小说网提供逆天小魔妃:帝君,咬一口!(一方素笺)第91章 差一点就成失足少女了!在线阅读,所有小说均免费阅读,努力打
-
2026-05-01 05:56:28
综合导航
成功
标题:英雄联盟之全华之梦_黑夜白术_第一百四十三章 少奋斗一百年_风云中文网
简介:风云中文网提供英雄联盟之全华之梦(黑夜白术)第一百四十三章 少奋斗一百年在线阅读,所有小说均免费阅读,努力打造最干净的阅
-
2026-04-20 17:54:45
综合导航
成功
标题:疯狂升级系统 - 第一千八百二十三章 面对 - 疯狂的萌萌 - 最新章节免费阅读无弹窗 - 福文小说
简介:《疯狂升级系统》疯狂的萌萌最新章节《 第一千八百二十三章 面对》,看到一群修炼者跪倒在地,十分恭敬,易天云一时间还愣住了
-
2026-04-15 05:09:31
综合导航
成功
标题:IXL Write a two-variable equation 6th grade math
简介:Improve your math knowledge with free questions in
-
2026-04-20 17:48:35
游戏娱乐
成功
标题:地铁跑酷手机版下载安装-地铁跑酷最新版免费下载安装 V3.33.0-m7软件园
简介:地铁跑酷最新版免费下载安装是一款经典好玩的跑酷游戏,地铁跑酷最新版免费下载安装给你最新的跑酷玩法让你在各个场景中每天玩不