Created
September 4, 2008 19:09
-
-
Save bryanwoods/8850 to your computer and use it in GitHub Desktop.
Hello/Goodbye in Cappuccino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import <Foundation/CPObject.j> | |
@implementation AppController : CPObject | |
{ | |
CPTextField label; | |
} | |
- (void)applicationDidFinishLaunching:(CPNotification)aNotification | |
{ | |
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask], | |
contentView = [theWindow contentView]; | |
label = [[CPTextField alloc] initWithFrame:CGRectMakeZero()]; | |
[label setAlignment:CPCenterTextAlignment]; | |
[label setStringValue:@"Hello World!"]; | |
[label setFont:[CPFont boldSystemFontOfSize:24.0]]; | |
[label sizeToFit]; | |
[label setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin]; | |
[label setFrameOrigin:CGPointMake((CGRectGetWidth([contentView bounds]) - CGRectGetWidth([label frame])) / 2.0, (CGRectGetHeight([contentView bounds]) - CGRectGetHeight([label frame])) / 2.0)]; | |
[contentView addSubview:label]; | |
var button = [[CPButton alloc] initWithFrame: CGRectMake( | |
CGRectGetWidth([contentView bounds])/2.0 - 40, | |
CGRectGetMaxY([label frame]) + 10, | |
80, 18 | |
)]; | |
[button setAutoresizingMask:CPViewMinXMargin | | |
CPViewMaxXMargin | | |
CPViewMinYMargin | | |
CPViewMaxYMargin]; | |
[button setTitle:"swap"]; | |
[button setTarget:self]; | |
[button setAction:@selector(swap:)]; | |
[contentView addSubview:button]; | |
[theWindow orderFront:self]; | |
[CPMenu setMenuBarVisible:YES]; | |
} | |
- (void)swap:(id)sender | |
{ | |
if ([label stringValue] == "Hello World!") | |
[label setStringValue:"Goodbye!"]; | |
else | |
[label setStringValue:"Hello World!"]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment