0
我想根據用戶通過單選按鈕選擇分鐘(1分鐘,15分鐘,30分鐘,45分鐘等)將信息附加到文件上。對於每個單選按鈕,在switch語句中都有大小寫。我發現很難定期更新該文件,並且持續不斷地有人知道如何根據所選分鐘來做到這一點。 time_int是當前時間,update_point是文件需要更新的下一個時間間隔點?所以請幫助使用UPDATEFILE()方法。連續文件更新,遞歸功能?
public void radioStartTime(int t) {
time_int = System.currentTimeMillis(); //time radio button is clicked, clock the time on click
System.out.println(sdf.format(time_int));
/* a case/situation for different radio button selected*/
switch (t) {
case 1:
update_point = time_int + (1*60000);
System.out.println(sdf.format(update_point));
UPDATEFILE????(1);
break;
.....
這對我來說太複雜了,我可以用do while while循環嗎?聽起來像(3)的方式,聽起來像 – user1106130 2012-03-02 11:34:56
@ user1106130。你創建一個線程來完成任務(文件更新),並用while包裝它,如:while(true或other condidtion){this.wait(yourinterval); updateFile();},但是你必須小心並處理一些細節,線程安全,阻塞等。 – Kent 2012-03-02 11:40:34