#import #import #import #import #import #import "AppKit/NSGraphics.h" #import #import #import #include @interface MyContentView: NSView { } @end @implementation MyContentView - (void) setFrame: (NSRect)frameRect { NSLog(@"Content view set frame to %@", NSStringFromRect(frameRect)); [super setFrame: frameRect]; } - (void) drawRect: (NSRect)rect { [[NSColor redColor] set]; NSRectFill(rect); } @end @interface AppController: NSObject { } @end @implementation AppController - (void)applicationDidFinishLaunching:(NSNotification *)notification { NSWindow *aWin; NSMenu *menu = [NSMenu new]; [menu addItemWithTitle: @"Quit" action: @selector(terminate:) keyEquivalent: @"q"]; [NSApp setMainMenu: menu]; RELEASE(menu); aWin = [[NSWindow alloc] initWithContentRect: NSMakeRect(200,200,140,140) styleMask: NSTitledWindowMask | NSResizableWindowMask backing: NSBackingStoreBuffered defer: NO]; [aWin setMaxSize: NSMakeSize(200, 200)]; [aWin setBackgroundColor: [NSColor blueColor]]; NSView *contentView = [[MyContentView alloc] initWithFrame: NSMakeRect(200,200,140,140)]; [aWin setContentView: contentView]; [contentView release]; [aWin makeKeyAndOrderFront: nil]; } @end int main (int argc, const char *argv[]) { CREATE_AUTORELEASE_POOL(pool); id app; app = [NSApplication sharedApplication]; [app setDelegate: [AppController new]]; [app run]; RELEASE(pool); return 0; }