0
我試圖製作一個程序,每10秒鐘就會衝一次F1鍵,就我所見,除非得到顯示「未報告的Exception AWTException;必須是抓住或宣佈被拋出「,在第14行與'新機器人();''強調是錯誤的。每10秒鐘按一次鍵
誰能幫助?`
package textreader;
import java.awt.AWTException;
import java.awt.event.KeyEvent;
import java.util.*;
import java.awt.Robot;
public class TextReader {
public static void main(String[] args) throws AWTException{
Timer t = new Timer();
t.schedule(new TimerTask() {
public void run(){
Robot r = new Robot();
r.keyPress(KeyEvent.VK_F1);
r.keyRelease(KeyEvent.VK_F1);
}
}, 0, 5000);
}
}
您需要用'try {Robot r = new Robot()} catch(AWTException e){// Catch block}''圍繞'Robot r = new Robot()'。 –