Sheets(Chapter 25 of Cocoa Programming for Mac OS X)

  1  //
  2  //   AppController.m
  3  //   TypingTutor
  4  //
  5  //   Created by b1mobile on 3/3/11.
  6  //   Copyright 2011 __MyCompanyName__. All rights reserved.
  7  //
  8 
  9  #import  " AppController.h "
 10  #import  " BigLetterView.h "
 11 
 12  #define  MAX_COUNT (100)
 13  // #define COUNT_STEP (5)
 14 
 15  @implementation AppController
 16 
 17  -  (id)init
 18  {
 19      [super init];
 20      
 21      letters  =  [[NSArray alloc] initWithObjects: @" a " @" s " @" d " @" f " @" j " @" k " @" l " @" ; " , nil];
 22      srandom(time(NULL));
 23      stepSize  =   5 ;
 24       return  self;
 25  }
 26 
 27  -  ( void )awakeFromNib
 28  {
 29      [self showAnotherLetter];
 30  }
 31      
 32  -  ( void )resetCount
 33  {
 34      [self willChangeValueForKey: @" count " ];
 35      count  =   0 ;
 36      [self didChangeValueForKey: @" count " ];
 37  }
 38 
 39  -  ( void )incrementCount
 40  {
 41      [self willChangeValueForKey: @" count " ];
 42      count  =  count  +  stepSize;
 43       if  (count  >  MAX_COUNT) 
 44      {
 45          count  =  MAX_COUNT;
 46      }
 47      [self didChangeValueForKey: @" count " ];
 48  }
 49 
 50  -  ( void )showAnotherLetter
 51  {
 52       int  x  =  lastIndex;
 53       while  (x  ==  lastIndex) 
 54      {
 55          x  =  random()  %  [letters count];
 56      }
 57      lastIndex  =  x;
 58      [outLetterView setString:[letters objectAtIndex:x]];
 59      
 60      [self resetCount];
 61  }
 62 
 63  -  (IBAction)stopGo:(id)sender
 64  {
 65       if  (timer  ==  nil) 
 66      {
 67          NSLog( @" Starting " );
 68          
 69          timer  =  [[NSTimer scheduledTimerWithTimeInterval: 1  target:self selector:@selector(checkThem) userInfo:nil repeats:YES] retain];
 70      }
 71       else  
 72      {
 73          NSLog( @" Stopping " );
 74          [timer invalidate];
 75          [timer release];
 76          timer  =  nil;
 77      }
 78  }
 79 
 80  -  ( void )checkThem:(NSTimer  * )aTimer
 81  {
 82       if ([[inLetterView  string ] isEqual:[outLetterView  string ]])
 83      {
 84          [self showAnotherLetter];
 85      }
 86       if  (count  ==  MAX_COUNT) 
 87      {
 88          NSBeep();
 89          [self resetCount];
 90      }
 91       else  
 92      {
 93          [self incrementCount];
 94      }
 95  }
 96 
 97  -  (IBAction)showSpeedSheet:(id)sender
 98  {
 99      [NSApp beginSheet:speedSheet modalForWindow:[inLetterView window] modalDelegate:nil didEndSelector:NULL contextInfo:NULL];
100  }
101 
102  -  (IBAction)endSpeedSheet:(id)sender
103  {
104      [NSApp endSheet:speedSheet];
105      [speedSheet orderOut:sender];
106  }
107 
108  @end

转载于:https://www.cnblogs.com/zhtf2014/archive/2011/03/08/1977484.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值