Anonymous user
Simple windowed application: Difference between revisions
m
→{{header|Objective-C}}: modernize
m (Omit from Logtalk) |
m (→{{header|Objective-C}}: modernize) |
||
Line 1,003:
@interface ClickMe : NSWindow
{
NSButton *
NSTextField *
int
}
- (void)applicationDidFinishLaunching: (NSNotification *)notification;
Line 1,013:
<lang objc>@implementation ClickMe : NSWindow
-(
{
NSButton *button = [[NSButton alloc] init];▼
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]
_button = button;
_text = text;
[[self
[[self
[self setTitle: @"Click Me!"];
▲ [self center];
}
return self;
}
- (void)applicationDidFinishLaunching: (NSNotification *)notification
Line 1,077 ⟶ 1,068:
- (void)advanceCounter: (id)sender
{
▲ [text setStringValue: [NSString stringWithFormat: @"Clicked %d times", counter]];
}
@end
Line 1,085 ⟶ 1,075:
int main()
{
@autoreleasepool {
ClickMe *clickme;▼
NSApplication *app = [NSApplication sharedApplication];▼
▲ ClickMe *clickme = [[ClickMe alloc] init];
[app setDelegate: clickme];▼
[app run];▼
}
▲ app = [NSApplication sharedApplication];
▲ [app setDelegate: clickme];
▲ [app run];
return 0;
}</lang>
|