標籤:screen 退出 close 沒有 opera operation etl err
之前用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 @Override40 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 }
>>>:
java調用exe程式實現延遲