日期:2014-05-20 浏览次数:20736 次
Timer timer = new Timer(); tt = new timertask(loginFrame); Button.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent event) { try{ timer.schedule(tt, 0, 1000*60*loginFrame.getti()); }catch(IllegalStateException e){ tt.cancel();//取消任务 tt = new timertask(loginFrame);//创建新任务 timer.schedule(tt, 0, 1000*60*loginFrame.getti()); } });
final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); class Task implements Runnable { ... } // class Task implements Callable {...} final ScheduledFuture<?> future = scheduler.schedule(new Task(), 10, TimeUnit.SECONDS); if(!future.isDone()){ future.cancel(); }