这是我自己参考资料写了一个java定时器

源代码在线查看: weekalarm.java

软件大小: 28 K
上传用户: xfzzp_0321
关键词: java 参考资料 定时器
下载地址: 免注册下载 普通下载 VIP

相关代码

				package dark.timer.example;
				import java.text.SimpleDateFormat;
				import java.util.Date;
				
				import org.tiling.scheduling.Scheduler;
				import org.tiling.scheduling.SchedulerTask;
				
				import dark.timer.WeekIterator;
				
				public class WeekAlarm
				{
				
					private final Scheduler scheduler = new Scheduler();
				
					private final SimpleDateFormat dateFormat =
						new SimpleDateFormat("dd MMM yyyy HH:mm:ss.SSS");
				
					private final int dayOfWeek,hourOfDay, minute, second;
				
					public WeekAlarm(int dayOfWeek,int hourOfDay, int minute, int second)
					{
						this.dayOfWeek = dayOfWeek;
						this.hourOfDay = hourOfDay;
						this.minute = minute;
						this.second = second;
					}
				
					public void start()
					{
						scheduler.schedule(new SchedulerTask()
						{
							public void run()
							{
								soundAlarm();
							}
							private void soundAlarm()
							{
								System.out.println(
									"Wake up! " + "It's " + dateFormat.format(new Date()));
								// Start a new thread to sound an alarm...
							}
						}, new WeekIterator(dayOfWeek,hourOfDay, minute, second));
					}
				
					public static void main(String[] args)
					{
						WeekAlarm alarmClock = new WeekAlarm(2,12, 57, 0);
						alarmClock.start();
					}
				}
							

相关资源