我有一個實現Actionlistener
的類。點擊這個班的按鈕後,我希望它在我指定的時間,以前和其他地方執行某些操作。所以我做了這些類:獲取操作監聽器中的系統時間
class DoSomething implements ActionListener{
public void actionPerformed(ActionEvent a){
while(true){
String test = obtainTime.time;
if(test.matches("(.*)17:29:30(.*)")){
Class.doSomethingMethod();
}
//Rest of the code
}
}
}
class ObtainTime{
static DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
static Calendar cal = Calendar.getInstance();
static String time = dateFormat.format(cal.getTime());
}
所以問題是,我只有從點擊它的時間。第二件事是按鈕變得不可點擊,因爲它仍在運行,有沒有辦法在代碼仍然在後臺運行時再次點擊?感謝您的任何幫助。
你需要使用線程使用
SwingWorker
樣子:它可以如下完成。 – SLaks 2013-03-14 17:31:06你從來沒有設置這些靜態字段 – SLaks 2013-03-14 17:58:42