예제 #1
0
        static void Main(string[] args)

        {
            MyClock mC = new MyClock();

            Console.WriteLine("请输入你的闹钟时间:");

            try

            {
                Console.WriteLine("几点:");

                mC.hour = Console.ReadLine();

                Console.WriteLine("几分:");

                mC.minute = Console.ReadLine();;

                Console.WriteLine("几秒:");

                mC.secord = Console.ReadLine();;
            }

            catch

            {
            }

            mC.Clock += new AlarmClock(ClockShow);

            mC.RingOrShow(mC.hour, mC.minute, mC.secord);
        }
예제 #2
0
        static void Main(string[] args)
        {
            MyClock clock = new MyClock();

            clock.OnTime += new ClickHandler(clock_2);
            clock.OnTime += new ClickHandler(clock_1);
            while (true)
            {
                clock.Time(DateTime.Now.ToString("T"));
                Thread.Sleep(5000);
            }
        }
예제 #3
0
        static void Main(string[] args)
        {
            try
            {
                MyClock  clock = new MyClock(); //时钟
                MyAlarm  alarm = new MyAlarm(); //闹铃
                DateTime now   = DateTime.Now;

                clock.AddAlarmTime(
                    new MyTime(now.Hour, now.Minute, now.Second + 5));;
                clock.AlarmEvent += alarm.Alarming;
                clock.Run();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
예제 #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("请设置闹钟时间:");
            int    year, month, day, h, m, s;
            string year1, month1, day1, h1, m1, s1;

            Console.Write("年:");
            year1 = Console.ReadLine();
            Console.Write("月:");
            month1 = Console.ReadLine();
            Console.Write("日:");
            day1 = Console.ReadLine();
            Console.Write("时:");
            h1 = Console.ReadLine();
            Console.Write("分:");
            m1 = Console.ReadLine();
            Console.Write("秒:");
            s1 = Console.ReadLine();
            try
            {
                year  = int.Parse(year1);
                month = int.Parse(month1);
                day   = int.Parse(day1);
                h     = int.Parse(h1);
                m     = int.Parse(m1);
                s     = int.Parse(s1);
            }
            catch
            {
                Console.WriteLine("输入错误,请输入整数!");
                return;
            }
            Console.WriteLine("闹钟已启动,请勿关闭!");
            DateTime date1 = DateTime.Now;
            DateTime date2 = new DateTime(year, month, day, h, m, s);
            TimeSpan ts    = date2 - date1;
            MyClock  clock = new MyClock();

            clock.TimeOut += new TimeoutHander(timeOut1);
            clock.TimeOut += new TimeoutHander(timeOut2);
            //Console.WriteLine(ts.Days+" "+ts.Hours+" "+ts.Minutes+" "+ts.Seconds);
            Thread.Sleep(ts);
            clock.Timeout(date2);
        }