private void fireBtn_Click(object sender, RoutedEventArgs e)
        {
            FireAlarm        fireAlarm   = new FireAlarm();
            FireHandlerClass fireHandler = new FireHandlerClass(fireAlarm);
            FireWatcherClass fireWatcher = new FireWatcherClass(fireAlarm);

            fireAlarm.ActivateFireAlarm(roomTxtBox.Text, int.Parse(ferocityTxtBox.Text));
        }
    public static void Main()
    {
        // Create an instance of the class that will be firing an event.

        FireAlarm myFireAlarm = new FireAlarm();

        // Create an instance of the class that will be handling the event. Note that
        // it receives the class that will fire the event as a parameter.

        FireHandlerClass myFireHandler = new FireHandlerClass(myFireAlarm);

        //use our class to raise a few events and watch them get handled
        myFireAlarm.ActivateFireAlarm("Kitchen", 3);
        myFireAlarm.ActivateFireAlarm("Study", 1);
        myFireAlarm.ActivateFireAlarm("Porch", 5);
        Console.ReadLine();
        return;
    }   //end of main
Beispiel #3
0
        private void btn2_Click(object sender, RoutedEventArgs e)
        {
            clearComments();

            OutStr.sw           = new StreamWriter("dataout.txt");
            OutStr.sw.AutoFlush = true;

            //定义一个火情发生源类对象;
            FireAlarm myFireAlarm = new FireAlarm();
            //定义一个火情处理类对象,并将源类对象作为参数传递给这个对象
            //FireHandlerClass myFireHandler1 = new FireHandlerClass(myFireAlarm);
            FireWatcherClass myFireHandle2 = new FireWatcherClass(this, myFireAlarm);

            //发生一种火情,以事件机制执行
            myFireAlarm.ActivateFireAlarm("Kitchen", 3);
            myFireAlarm.ActivateFireAlarm("Kitchen", 6);

            OutStr.sw.Close();
        }