⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 screenframe.java

📁 每次使用截屏 第一想到的就是QQ。每次都要打开
💻 JAVA
字号:
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());
  
 }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -