写了stanford cs195
assignment 2,
/* ConvertController */
#import < Cocoa / Cocoa.h >
#import " ConvertModel.h "
@interface ConvertController : NSObject
{
IBOutlet NSSlider *celsiusSlider;
IBOutlet NSTextField *celsiusField;
IBOutlet ConvertModel *converter;
IBOutlet NSTextField *fehrenheitField;
IBOutlet NSSlider *fehrenheitSlider;
}
- (IBAction)convert:(id)sender;
- ( void )updateCelsius:( float )_c andFehrenheit:( float )_f;
@end
#import < Cocoa / Cocoa.h >
#import " ConvertModel.h "
@interface ConvertController : NSObject
{
IBOutlet NSSlider *celsiusSlider;
IBOutlet NSTextField *celsiusField;
IBOutlet ConvertModel *converter;
IBOutlet NSTextField *fehrenheitField;
IBOutlet NSSlider *fehrenheitSlider;
}
- (IBAction)convert:(id)sender;
- ( void )updateCelsius:( float )_c andFehrenheit:( float )_f;
@end
#import
"
ConvertController.h
"
#import " ConvertModel.h "
@implementation ConvertController
- (IBAction)convert:(id)sender
{
float celsius, fehrenheit;
if ((sender==celsiusSlider) || (sender == celsiusField)) {
celsius = [sender floatValue];
[converter setA:9.0/5.0];
[converter setB:32];
fehrenheit = [converter y:celsius];
} else {
fehrenheit =[sender floatValue];
[converter setA:5.0/9.0];
[converter setB:-160.0/9.0];
celsius = [converter y:fehrenheit];
}
[self updateCelsius:celsius andFehrenheit:fehrenheit];
}
- ( void )updateCelsius:( float )_c andFehrenheit:( float )_f
{
NSColor *fillColor_c =[[NSColor blueColor]blendedColorWithFraction:(_c/100.0) ofColor:[NSColor redColor]];
NSColor *fillColor_f =[[NSColor blueColor]blendedColorWithFraction:(_f/212.0) ofColor:[NSColor redColor]];
[celsiusField setTextColor:fillColor_c];
[celsiusField setFloatValue:_c];
[celsiusSlider setFloatValue:_c];
[fehrenheitField setTextColor:fillColor_f];
[fehrenheitSlider setFloatValue:_f];
[fehrenheitField setFloatValue:_f];
}
@end
#import " ConvertModel.h "
@implementation ConvertController
- (IBAction)convert:(id)sender
{
float celsius, fehrenheit;
if ((sender==celsiusSlider) || (sender == celsiusField)) {
celsius = [sender floatValue];
[converter setA:9.0/5.0];
[converter setB:32];
fehrenheit = [converter y:celsius];
} else {
fehrenheit =[sender floatValue];
[converter setA:5.0/9.0];
[converter setB:-160.0/9.0];
celsius = [converter y:fehrenheit];
}
[self updateCelsius:celsius andFehrenheit:fehrenheit];
}
- ( void )updateCelsius:( float )_c andFehrenheit:( float )_f
{
NSColor *fillColor_c =[[NSColor blueColor]blendedColorWithFraction:(_c/100.0) ofColor:[NSColor redColor]];
NSColor *fillColor_f =[[NSColor blueColor]blendedColorWithFraction:(_f/212.0) ofColor:[NSColor redColor]];
[celsiusField setTextColor:fillColor_c];
[celsiusField setFloatValue:_c];
[celsiusSlider setFloatValue:_c];
[fehrenheitField setTextColor:fillColor_f];
[fehrenheitSlider setFloatValue:_f];
[fehrenheitField setFloatValue:_f];
}
@end
#import
"
ConvertModel.h
"
@implementation ConvertModel
- ( void )setA:( float ) _a {
a=_a;
}
- ( void )setB:( float )_b {
b=_b;
}
- ( float ) y:( float ) x {
return a*x+b;
}
@end
@implementation ConvertModel
- ( void )setA:( float ) _a {
a=_a;
}
- ( void )setB:( float )_b {
b=_b;
}
- ( float ) y:( float ) x {
return a*x+b;
}
@end
/* ConvertModel */
#import < Cocoa / Cocoa.h >
@interface ConvertModel : NSObject
{
float a,b;
}
- ( void )setA:( float )_a;
- ( void )setB:( float )_b;
- ( float )y:( float )x ;
@end
#import < Cocoa / Cocoa.h >
@interface ConvertModel : NSObject
{
float a,b;
}
- ( void )setA:( float )_a;
- ( void )setB:( float )_b;
- ( float )y:( float )x ;
@end