java录屏_java录屏⼩⼯具源码(idea)
【实例简介】录制的视频保存在 pdir ⽬录,windows通常为 C:\Users\Administrator\AppData\Local\Temp 【实例截图】
点击播放后,效果如下:
【核⼼代码】
import java.awt.AWTException;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileChannel.MapMode;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import urrent.BlockingQueue;
import urrent.ExecutorService;
import urrent.Executors;
import urrent.LinkedBlockingQueue; import urrent.ScheduledExecutorService; import urrent.TimeUnit;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
import javax.imageio.ImageIO;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.DataLine;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.TargetDataLine;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
/**
* java录像⼩程序: 视频⽂件保存在系统临时⽬录, 回车全屏播放, ESC退出全屏播放
* @author dgqjava
*
*/
@SuppressWarnings("serial")
public class MainFrame extends JFrame {
private static final int WIDTH = 200;
private static final int HEIGHT = 70;
private static final Color BUTTON_COLOR = new Color(155, 183, 214);
private static final Color BUTTON_FOCUS_COLOR = new Color(87, 156, 242);
private static final Color BUTTON_DISABLE_COLOR = new Color(180, 207, 229); private static final Font BUTTON_FONT = new Font("华⽂⾏楷", Font.BOLD, 15);
private static final String DEFAULT_FILE_PATH = Property("pdir"); private static Dimension screenSize;
private final JButton start = new JButton("开始");
private final JButton pause = new JButton("暂停");
private final JButton restart = new JButton("继续");
private final JButton stop = new JButton("完成");
private final JButton play = new JButton("播放");
private final JButton close = new JButton("退出");
private String currentFilePath;
public MainFrame() {
setUndecorated(true);
setSize(WIDTH, HEIGHT);
Toolkit tk = DefaultToolkit();
screenSize = tk.getScreenSize();
setLocation((int) Width() - WIDTH, (int) (Height() -tk.getScreenInsets(getGraphicsConfiguration()).bottom - HEIGHT));
MouseListener buttonMouseListener = new MouseAdapter() {
public void mouseEntered(MouseEvent e) {
JButton btn = (JButton) e.getSource();
if(btn.isEnabled()) {
btn.setBackground(BUTTON_FOCUS_COLOR);
}
}
public void mouseExited(MouseEvent e) {
JButton btn = (JButton) e.getSource();
java影视app源码
if(btn.isEnabled()) {
btn.setBackground(BUTTON_COLOR);
}
}
};
start.addMouseListener(buttonMouseListener);
pause.addMouseListener(buttonMouseListener);
restart.addMouseListener(buttonMouseListener);
stop.addMouseListener(buttonMouseListener);
play.addMouseListener(buttonMouseListener);
close.addMouseListener(buttonMouseListener);
ChangeListener changeListener = new ChangeListener() {
public void stateChanged(ChangeEvent e) {
JButton btn = (JButton) e.getSource();
if(btn.isEnabled()) {
btn.setBackground(BUTTON_COLOR);
} else {
btn.setBackground(BUTTON_DISABLE_COLOR);
}
}
};
start.addChangeListener(changeListener);
pause.addChangeListener(changeListener);
restart.addChangeListener(changeListener);
stop.addChangeListener(changeListener);
play.addChangeListener(changeListener);
start.setFont(BUTTON_FONT);
pause.setFont(BUTTON_FONT);
restart.setFont(BUTTON_FONT);
stop.setFont(BUTTON_FONT);
play.setFont(BUTTON_FONT);
close.setFont(BUTTON_FONT);
start.setBackground(BUTTON_COLOR);
pause.setBackground(BUTTON_DISABLE_COLOR);
restart.setBackground(BUTTON_DISABLE_COLOR);
stop.setBackground(BUTTON_DISABLE_COLOR);
play.setBackground(BUTTON_DISABLE_COLOR);
close.setBackground(BUTTON_COLOR);
pause.setEnabled(false);
restart.setEnabled(false);
stop.setEnabled(false);
play.setEnabled(false);
start.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
start.setEnabled(false);
pause.setEnabled(true);
stop.setEnabled(true);
play.setEnabled(false);
currentFilePath = DEFAULT_FILE_PATH System.currentTimeMillis(); RecordHelper.start(currentFilePath);
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。