Simple windowed application: Difference between revisions

m
m (Omit from Logtalk)
Line 1,003:
@interface ClickMe : NSWindow
{
NSButton *button_button;
NSTextField *text_text;
int counter_counter;
}
- (void)applicationDidFinishLaunching: (NSNotification *)notification;
Line 1,013:
 
<lang objc>@implementation ClickMe : NSWindow
-(idinstancetype) init
{
NSButton *button = [[NSButton alloc] init];
NSRect buttonRect;
int totalWindowHeight;
 
counter = 0;
button = [[NSButton alloc] init];
[button setButtonType: NSToggleButton];
[button setTitle: @"Click Me"];
Line 1,025 ⟶ 1,021:
[button setTarget: self];
[button setAction: @selector(advanceCounter:)];
NSRect buttonRect = [button frame];
 
NSTextField *text = [[NSTextField alloc]
initWithFrame: NSMakeRect(buttonRect.origin.x, buttonRect.size.height,
buttonRect.size.width, buttonRect.size.height)];
Line 1,039 ⟶ 1,035:
setFrameSize: NSMakeSize( [text frame].size.width, buttonRect.size.height ) ];
 
int totalWindowHeight = buttonRect.size.height + [text frame].size.height;
 
if ((self = [super initWithContentRect: NSMakeRect(100, 100,
[self
initWithContentRect: NSMakeRect(100, 100,
[text frame].size.width, totalWindowHeight)
styleMask: (NSTitledWindowMask | NSClosableWindowMask)
backing: NSBackingStoreBuffered
defer: NO];)) {
counter _counter = 0;
 
_button = button;
[[self contentView] addSubview: text]; [text release];
_text = text;
[[self contentView] addSubview: button]; [button release];
 
[[self setTitle:contentView] @"ClickaddSubview: Me!"_text];
[[self centercontentView] addSubview: _button];
 
[self setTitle: @"Click Me!"];
[self center];
}
return self;
}
 
 
-(void) dealloc
{
[button release];
[text release];
[super dealloc];
}
 
- (void)applicationDidFinishLaunching: (NSNotification *)notification
Line 1,077 ⟶ 1,068:
- (void)advanceCounter: (id)sender
{
[text_text setStringValue: [NSString stringWithFormat: @"Clicked %d times", counter++_counter]];
counter++;
[text setStringValue: [NSString stringWithFormat: @"Clicked %d times", counter]];
}
@end
Line 1,085 ⟶ 1,075:
int main()
{
@autoreleasepool {
ClickMe *clickme;
NSApplication *app = [NSApplication sharedApplication];
NSAutoreleasePool *pool;
ClickMe *clickme = [[ClickMe alloc] init];
NSApplication *app;
[app setDelegate: clickme];
 
[app run];
pool = [[NSAutoreleasePool alloc] init];
}
app = [NSApplication sharedApplication];
clickme = [[ClickMe alloc] init];
[app setDelegate: clickme];
[app run];
[clickme release];
[pool release];
return 0;
}</lang>
Anonymous user