为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

java模拟QQ的截屏(代码)

2018-01-18 9页 doc 26KB 37阅读

用户头像

is_731942

暂无简介

举报
java模拟QQ的截屏(代码)java模拟QQ的截屏(代码) javaÄ?ÄâQQµÄ?ØÆÁ(?úÂë) package com.xfsuper.util.screenCamera; import java.awt.AWTException; import java.awt.Dimension; import java.awt.Rectangle; import java.awt.Robot; import java.awt.Toolkit; import java.awt.image.BufferedImage; import java...
java模拟QQ的截屏(代码)
java模拟QQ的截屏(代码) javaÄ?ÄâQQµÄ?ØÆÁ(?úÂë) package com.xfsuper.util.screenCamera; import java.awt.AWTException; import java.awt.Dimension; import java.awt.Rectangle; import java.awt.Robot; import java.awt.Toolkit; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; public class GuiCamera { String fileName="GuiCamera"; String imageFormat="png"; int num=0; Dimension d=Toolkit.getDefaultToolkit().getScreenSize(); public GuiCamera() { } public GuiCamera(String fileName,String imageFormat) { this.fileName=fileName; this.imageFormat=imageFormat; } public void snpaShot(int startX,int startY,int endX,int endY) { try { num++; int width=startX>endX?startX-endX:endX-startX; int height=startY>endY?startY-endY:endY-startY; int temp; if(startX>endX) { temp=startX; startX=endX; endX=temp; } if(startY>endY) { temp=startY; startY=endY; endY=temp; } // BufferedImage bImage=(new Robot()).createScreenCapture(new Rectangle(0,0,(int)d.getWidth(),(int)d.getHeight())); BufferedImage bImage=(new Robot()).createScreenCapture(new Rectangle(startX,startY,width,height)); String name=fileName+String.valueOf(num)+"."+imageFormat; File f=new File(name); ImageIO.write(bImage,imageFormat,f); } catch (AWTException e) { // TODO ×Ô??Éú?É catch ?é e.printStackTrace(); } catch (IOException e) { // TODO ×Ô??Éú?É catch ?é e.printStackTrace(); } } public static void main(String[] args) { // new GuiCamera("d:\\image","png").snpaShot(); } public String getFileName() { return fileName; } public void setFileName(String fileName) { this.fileName = fileName; } public String getImageFormat() { return imageFormat; } public void setImageFormat(String imageFormat) { this.imageFormat = imageFormat; } } /////////////////////////////////////////////////////////////// package com.xfsuper.util.screenCamera; import java.awt.*; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import javax.swing.*; public class ScreenFrame extends JFrame implements MouseMotionListener, MouseListener{ JPanel jp; Image Background; Point p0; Point p1; int startx,starty,endx,endy; public ScreenFrame() { jp = new JPanel(); Toolkit tk =Toolkit.getDefaultToolkit(); Dimension dm = tk.getScreenSize(); this.getContentPane().add(jp); try { Robot r = new Robot(); Background = r.createScreenCapture(new Rectangle(0,0,(int)dm.getWidth(), (int)dm.getHeight())); } catch(Exception e) { //e.printStackTrace(); } this.resize((int)dm.getWidth(), (int)dm.getHeight()+31); //this.setSize(300,300); this.setLocation(0,-30); this.addMouseListener(this); this.addMouseMotionListener(this); this.setVisible(true); } public void paint(Graphics g) { p0 = this.getLocationOnScreen(); p1 = new Point(-p0.x, -p0.y); //draw background g.drawImage(Background, p1.x, p1.y, null); //draw Rect int width=startx>endx?startx-endx:endx-startx; int height=starty>endy?starty-endy:endy-starty; if(endy>starty) g.drawRect(startx+2,starty+31,width-4,height-31); else g.drawRect(endx,endy,width,height+31); //Graphics2D g2d = (Graphics2D)g; //repaint(); } public static void main(String args[]) { new ScreenFrame(); } public void mouseClicked(MouseEvent e) { if(e.getButton()==3) { System.exit(1); } } public void mouseEntered(MouseEvent e) { // TODO ×Ô??Éú?É?????æ?ù } public void mouseExited(MouseEvent e) { // TODO ×Ô??Éú?É?????æ?ù } public void mousePressed(MouseEvent e) { if(e.getButton()==1) { System.out.println(e.getY()); startx=e.getX()-4; starty=e.getY()-31; } } public void mouseReleased(MouseEvent e) { //System.out.println(e.getY()); if(e.getButton()==1) { endx=e.getX(); endy=e.getY()-31; System.out.println("startX="+startx+" starty="+starty+" endx="+endx+" endy="+endy); new GuiCamera("d:\\image","png").snpaShot(startx,starty,endx,endy); } } public void mouseDragged(MouseEvent e) { //System.out.println("x="+e.getX()+" y="+e.getY()); endx=e.getX(); endy=e.getY(); repaint(); } public void mouseMoved(MouseEvent e) { //System.out.println("x="+e.getX()+" y="+e.getY()); } } ////////////////////////////////////////// package com.xfsuper.util.screenCamera; import java.awt.Color; import java.awt.Container; import java.awt.Graphics; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import javax.swing.JFrame; public class MouseMovePoint extends JFrame implements MouseMotionListener,MouseListener{ Container con=this.getContentPane(); public MouseMovePoint() { this.addMouseMotionListener(this); this.addMouseListener(this); this.repaint(); this.setSize(500,500); this.setResizable(false); this.setVisible(true); } public void paint(Graphics g) { //super.paintComponents(g); g.setColor(Color.red); g.drawLine(100,100,200,200); } public static void main(String[] args) { new MouseMovePoint(); } public void mouseDragged(MouseEvent e) { System.out.println("x="+e.getX()+" y="+e.getY()); } public void mouseMoved(MouseEvent e) { } public void mouseClicked(MouseEvent e) { } public void mouseEntered(MouseEvent e) { } public void mouseExited(MouseEvent e) { } public void mousePressed(MouseEvent e) { System.out.println(e.getX()); } public void mouseReleased(MouseEvent e) { System.out.println(e.getX()); } }
/
本文档为【java模拟QQ的截屏(代码)】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索