Popular Posts

There was an error in this gadget

Mar 29, 2011

Making Calculator For iPhone!!


- create a window based project
- open interface builder and create a view name it Untitled.xib
- create UIViewControllerSubclass with implementation file.
- give the name of the file untitled
- interface and implementation file will be created.
- open your AppDelegate.h file
- type the code bellow….

Name your xib file as Untitled.xib
- Set the File's Owner class
- add two text Field, a level, and four button for add, subtract, multiply, division.
- select and right click on file owner and connect the reference with the view.


//
//  EtcProjectAppDelegate.h
//  EtcProject
//
//  Created by JUBAYER Ahmed on 3/28/11.
//  Copyright CODEMAGNETS 2011. All rights reserved.
//

#import <UIKit/UIKit.h>

@class untitled;

@interface EtcProjectAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
untitled *viewController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet untitled *viewController;

@end


//
//  EtcProjectAppDelegate.m
//  EtcProject
//
//  Created by JUBAYER Ahmed on 3/28/11.
//  Copyright CODEMAGNETS 2011. All rights reserved.
//

#import "EtcProjectAppDelegate.h"
#import "untitled.h"

@implementation EtcProjectAppDelegate

@synthesize window;
@synthesize viewController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

untitled *viewController = [[untitled alloc] initWithNibName:@"Untitled" bundle:[NSBundle mainBundle]];
[window addSubview:[viewController view]];

// Override point for customization after app launch    
    //[window addSubview:viewController.view];
    [window makeKeyAndVisible];
return YES;
}


- (void)dealloc {
[viewController release];
    [window release];
    [super dealloc];
}


@end





//
//  untitled.h
//  EtcProject
//
//  Created by JUBAYER Ahmed on 3/28/11.
//  Copyright 2011 CODEMAGNETS. All rights reserved.
//

#import <UIKit/UIKit.h>


@interface untitled : UIViewController {
IBOutlet UITextField *textField1;
IBOutlet UITextField *textField2;
    IBOutlet UILabel *label;
}
-(IBAction) Addition;
-(IBAction) SubTrac;
-(IBAction) Multi;
-(IBAction) Divi;

@end


    //
//  untitled.m
//  EtcProject
//
//  Created by JUBAYER Ahmed on 3/28/11.
//  Copyright 2011 CODEMAGNETS. All rights reserved.
//

#import "untitled.h"


@implementation untitled

-(IBAction) Addition{
float number1 = [textField1.text floatValue];
float number2 = number1 + ([textField2.text floatValue]);
label.text = [[NSString alloc] initWithFormat:@"%.2f", number2];
}

-(IBAction) SubTrac{
    float number1 = [textField1.text floatValue];
float number2 = number1 - ([textField2.text floatValue]);
label.text = [[NSString alloc] initWithFormat:@"%f", number2];
}

-(IBAction) Multi{
float number1 = [textField1.text floatValue];
    float number2 = number1 * ([textField2.text floatValue]);
label.text = [[NSString alloc] initWithFormat:@"%f",number2];
}

-(IBAction) Divi{
float number1 = [textField1.text floatValue];
float number2 = number1 / ([textField2.text floatValue]);
label.text = [[NSString alloc] initWithFormat:@"%f",number2]; 
}


- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end












No comments:

Post a Comment