java调用exe截图程序实现延迟截图
之前用Apple键盘,在windows系统上没有快速全屏截图工具,无法截取下拉菜单之类的点击其他地方就会消失的图片,
又不想写那么复杂,就使用java写了简单调用exe截图程序来实现延迟截图
1 import javax.swing.*; 2 import java.awt.event.ActionEvent; 3 import java.awt.event.ActionListener; 4 5 /** 6 * Created by ycl on 2017/8/17 2017-8-17 22:33:59. 7 */ 8 public class CutScreen extends JFrame implements ActionListener { 9 10 11 JPanel jp; 12 JLabel jlTime; 13 JComboBox jcbTime; 14 JButton jbTime; 15 16 public CutScreen() { 17 jp = new JPanel(); 18 this.setContentPane(jp); 19 this.setTitle("延迟截图"); 20 this.setVisible(true); 21 jp.setLayout(null); 22 jlTime = new JLabel("Delay Time:"); 23 jlTime.setBounds(25, 15, 100, 30); 24 jp.add(jlTime); 25 26 String[] str = new String[]{"1", "2", "3", "5", "10"}; 27 jcbTime = new JComboBox(str); 28 jcbTime.setBounds(110, 15, 100, 30); 29 jp.add(jcbTime); 30 jbTime = new JButton("Start"); 31 jbTime.addActionListener(this); 32 jbTime.setBounds(220, 15, 70, 30); 33 jp.add(jbTime); 34 35 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 36 this.setBounds(600, 300, 325, 100); 37 } 38 39 @Override 40 public void actionPerformed(ActionEvent e) { 41 if (e.getSource() == jbTime) { 42 String time = jcbTime.getSelectedItem().toString(); 43 try { 44 this.setExtendedState(JFrame.ICONIFIED); //点击后窗口最小化 45 Thread.sleep(Integer.parseInt(time) * 1000); 46 openExe(); 47 System.exit(0); //启动exe程序后退出主程序 48 } catch (InterruptedException e1) { 49 e1.printStackTrace(); 50 } 51 } 52 } 53 54 //执行exe程序,也是网上copy的 55 public static void openExe() { 56 final Runtime runtime = Runtime.getRuntime(); 57 Process process = null; 58 59 try { 60 process = runtime.exec("D:\\Software\\tengxunjt.exe"); 61 62 } catch (final Exception e) { 63 System.out.println("Error exec!"); 64 } 65 } 66 67 public static void main(String[] args) { 68 new CutScreen(); 69 } 70 }
>>>效果图: