Created
September 21, 2008 10:58
-
-
Save tlrobinson/11857 to your computer and use it in GitHub Desktop.
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 _field; | |
CPURLConnection _submitConnection; | |
CPURLConnection _loadConnection; | |
} | |
- (void)applicationDidFinishLaunching:(CPNotification)aNotification | |
{ | |
var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask], | |
contentView = [theWindow contentView]; | |
var _field = [[CPTextField alloc] initWithFrame:CGRectMakeZero()]; | |
[_field setEditable:YES]; | |
[_field setStringValue:@"Hello World!"]; | |
[_field setFont:[CPFont boldSystemFontOfSize:24.0]]; | |
[_field sizeToFit]; | |
[_field setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin]; | |
[_field setFrameOrigin:CGPointMake((CGRectGetWidth([contentView bounds]) - CGRectGetWidth([_field frame])) / 2.0, (CGRectGetHeight([contentView bounds]) - CGRectGetHeight([_field frame])) / 2.0)]; | |
[_field setBordered:YES]; | |
[_field setBezeled:YES]; | |
[_field setBezelStyle:CPTextFieldSquareBezel]; | |
[contentView addSubview:_field]; | |
var submitButton = [[CPButton alloc] initWithFrame:CGRectMakeZero()]; | |
[submitButton setTitle:"Submit"]; | |
[submitButton sizeToFit]; | |
[submitButton setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin]; | |
[submitButton setFrameOrigin:CGPointMake((CGRectGetWidth([contentView bounds]) - CGRectGetWidth([submitButton frame])) / 2.0, (CGRectGetHeight([contentView bounds]) - CGRectGetHeight([submitButton frame])) / 2.0 + 30)]; | |
[submitButton setAction:@selector(submit:)]; | |
[submitButton setTarget:self]; | |
[contentView addSubview:submitButton]; | |
var loadButton = [[CPButton alloc] initWithFrame:CGRectMakeZero()]; | |
[loadButton setTitle:"Load"]; | |
[loadButton sizeToFit]; | |
[loadButton setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin]; | |
[loadButton setFrameOrigin:CGPointMake((CGRectGetWidth([contentView bounds]) - CGRectGetWidth([loadButton frame])) / 2.0, (CGRectGetHeight([contentView bounds]) - CGRectGetHeight([loadButton frame])) / 2.0 + 60)]; | |
[loadButton setAction:@selector(load:)]; | |
[loadButton setTarget:self]; | |
[contentView addSubview:loadButton]; | |
[theWindow orderFront:self]; | |
} | |
- (void)load:(id)sender | |
{ | |
_loadConnection = [CPURLConnection connectionWithRequest:[CPURLRequest requestWithURL: "http://localhost:8088/load.php"] delegate:self]; | |
} | |
- (void)submit:(id)sender | |
{ | |
_submitConnection = [CPURLConnection connectionWithRequest:[CPURLRequest requestWithURL: "http://localhost:8088/submit.php?test="+encodeURIComponent([_field stringValue])] delegate:self]; | |
} | |
- (void)connection:(CPURLConnection)aConnection didReceiveData:(CPString)data | |
{ | |
if (aConnection == _submitConnection) | |
{ | |
alert("got back: " + data); | |
} | |
else if (aConnection == _loadConnection) | |
{ | |
alert("loaded: " + data); | |
} | |
} | |
- (void)connection:(CPURLConnection)aConnection didFailWithError:(CPError)anError | |
{ | |
alert("failure! "+anError+" ("+aConnection+")") | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment