• 大小: 23KB
    文件类型: .java
    金币: 1
    下载: 0 次
    发布日期: 2021-05-22
  • 语言: Java
  • 标签: 截图  平台集成  

资源简介

java实现截图功能,类似QQ截图,直接导入就可以使用,

资源截图

代码片段和文件信息

/**
 * CaptureScreen.java
 */
import java.awt.*;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import javax.imageio.*;
import java.awt.image.*;

public class CaptureScreen extends Jframe implements ActionListener {
    private JButton startcancel;
    private JPanel c;
    private BufferedImage get;
    private JTabbedPane jtp;//一个放置很多份图片
    private int index;//一个一直会递增的索引用于标认图片
    private JRadioButton javasystem;//JAVA界面系统界面
    /** Creates a new instance of CaptureScreen */
    public CaptureScreen() {
        super(“屏幕截取“);
        try{
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }catch(Exception exe){
            exe.printStackTrace();
        }
        initWindow();
        initOther();
    }
    private void initOther(){
        jtp=new JTabbedPane(JTabbedPane.TOPJTabbedPane.SCROLL_TAB_LAYOUT);
    }
    private void initWindow(){
        start=new JButton(“开始截取“);
        cancel=new JButton(“退出“);
        start.addActionListener(this);
        cancel.addActionListener(this);
        JPanel buttonJP=new JPanel();
        c=new JPanel(new BorderLayout());
        JLabel jl=new JLabel(“屏幕截取“ JLabel.CENTER);
        JLabel jl1=new JLabel(“作者: gaowei“JLabel.CENTER);
        jl.setFont(new Font(“黑体“Font.BOLD40));
        jl1.setFont(new Font(“宋体“Font.BOLD20));
        jl.setForeground(Color.RED);
        jl1.setForeground(Color.BLUE);
        c.add(jlBorderLayout.CENTER);
        c.add(jl1BorderLayout.SOUTH);
        buttonJP.add(start);
        buttonJP.add(cancel);
        buttonJP.setBorder(BorderFactory.createtitledBorder(“公共操作区“));
        JPanel jp=new JPanel();//放置两个单选按钮的面板
        jp.add(java=new JRadioButton(“java界面“));
        jp.add(system=new JRadioButton(“系统界面“true));
        java.addActionListener(this);
        system.addActionListener(this);
        jp.setBorder(BorderFactory.createtitledBorder(“界面风格“));
        ButtonGroup bg=new ButtonGroup();
        bg.add(java);
        bg.add(system);
        JPanel all=new JPanel();
        all.add(jp);
        all.add(buttonJP);
        this.getContentPane().add(cBorderLayout.CENTER);
        this.getContentPane().add(allBorderLayout.SOUTH);
        this.setSize(500400);
        this.setLocationRelativeTo(null);
        this.setVisible(true);
        this.setAlwaysOnTop(true);
        this.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
    }
    
    private void updates(){
        this.setVisible(true);
        if(get!=null){
            //如果索引是0则表示一张图片都没有被加入过
            //则要清除当前的东西重新把tabpane放进来
            if(index==0){
                c.removeAll();
                c.add(jtpBorderLayout.CENTER);
            }else{//否则的话直接对tabpane添加面板就可以了
                //就什么都不用做了
            }

评论

共有 条评论