#import <AppKit/AppKit.h>

@interface AppController: NSObject
{
    id aTxt;
    NSTimer *aTmr;
    NSButton *endB;
}
@end


@implementation AppController

- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
    id aWin = [[NSWindow alloc] initWithContentRect: NSMakeRect (0,0,130,50)
            styleMask: NSTitledWindowMask
            backing: NSBackingStoreBuffered
            defer: YES];
    [aWin setFrameOrigin: NSMakePoint(100,100)];

    aTxt = [[NSTextField alloc] initWithFrame: NSMakeRect(5,5, 80, 25)];
    [aTxt setStringValue: @"Mem test"];
    endB = [[NSButton alloc] initWithFrame: NSMakeRect(90, 5,38,20)];
    [endB setTarget: NSApp];
    [endB setAction: @selector(terminate:)];
    [endB setTitle: @"end"];
    
    [[aWin contentView] addSubview: endB];  [endB release];
    [[aWin contentView] addSubview: aTxt];  [aTxt release];
    [aWin makeKeyAndOrderFront: nil];

    aTmr = [NSTimer scheduledTimerWithTimeInterval: 0.01
                                             target: self
                                           selector: @selector(timerFire:)
                                           userInfo: nil
                                            repeats: YES];
    [aTmr retain];
}

- (void) timerFire: (NSTimer *) aTmr
{
    [aTxt setNeedsDisplay: YES];
    // or
    //[aTxt display];
}

@end

int main(int argc, const char *argv[]) {
	id pool = [NSAutoreleasePool new];
	id app;

    app = [NSApplication sharedApplication];
	[app setDelegate: [AppController new]];
	[app run];

	[pool release];
	return 0;
}
