Guest User

Untitled

a guest
Feb 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. import <Foundation/CPObject.j>
  2.  
  3.  
  4. @implementation AppController : CPObject
  5. {
  6. CPTextField label;
  7. }
  8.  
  9. - (void)applicationDidFinishLaunching:(CPNotification)aNotification
  10. {
  11. var theWindow = [[CPWindow alloc] initWithContentRect:CGRectMakeZero() styleMask:CPBorderlessBridgeWindowMask],
  12. contentView = [theWindow contentView];
  13.  
  14. label = [[CPTextField alloc] initWithFrame:CGRectMakeZero()];
  15.  
  16. [label setAlignment:CPCenterTextAlignment];
  17. [label setStringValue:@"Hello World!"];
  18. [label setFont:[CPFont boldSystemFontOfSize:24.0]];
  19.  
  20. [label sizeToFit];
  21.  
  22. [label setAutoresizingMask:CPViewMinXMargin | CPViewMaxXMargin | CPViewMinYMargin | CPViewMaxYMargin];
  23. [label setFrameOrigin:CGPointMake((CGRectGetWidth([contentView bounds]) - CGRectGetWidth([label frame])) / 2.0, (CGRectGetHeight([contentView bounds]) - CGRectGetHeight([label frame])) / 2.0)];
  24.  
  25. [contentView addSubview:label];
  26.  
  27. var button = [[CPButton alloc] initWithFrame: CGRectMake(
  28. CGRectGetWidth([contentView bounds])/2.0 - 40,
  29. CGRectGetMaxY([label frame]) + 10,
  30. 80, 18
  31. )];
  32.  
  33. [button setAutoresizingMask:CPViewMinXMargin |
  34. CPViewMaxXMargin |
  35. CPViewMinYMargin |
  36. CPViewMaxYMargin];
  37. [button setTitle:"swap"];
  38.  
  39. [button setTarget:self];
  40. [button setAction:@selector(swap:)];
  41.  
  42. [contentView addSubview:button];
  43.  
  44. [theWindow orderFront:self];
  45.  
  46. [CPMenu setMenuBarVisible:YES];
  47. }
  48.  
  49. - (void)swap:(id)sender
  50. {
  51. if ([label stringValue] == "Hello World!")
  52. [label setStringValue:"Goodbye!"];
  53. else
  54. [label setStringValue:"Hello World!"];
  55. }
  56.  
  57. @end
Add Comment
Please, Sign In to add comment