java Timer定时器例子,javatimer定时器,一个java的Timer
分享于 点击 7059 次 点评:28
java Timer定时器例子,javatimer定时器,一个java的Timer
一个java的Timer定时器,每隔1秒钟刷新一次JLabel,5秒钟后退出系统。
private void initialTimer() { Timer timer = new Timer(); timer.schedule(new TimerTask() { int MAX_COUNTER = 5; int counter = 0; @Override public void run() { if (MAX_COUNTER == counter) { if (!isExitCB.isSelected()) { System.exit(0); } else { this.cancel(); } } willExitLabel.setText("System will exit within " + (MAX_COUNTER - counter) + " seconds"); counter++; } }, 0, 1000); }
用户点评