- (void)buttonAction:(id)sender
{
NSBeep();
}
- (void)createWindow
{
// create a window
NSRect contentRect = NSMakeRect(0.0, 0.0, 250.0, 150.0);
NSUInteger style = NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask;
NSWindow *window = [[NSWindow alloc] initWithContentRect:contentRect styleMask:style backing:NSBackingStoreBuffered defer:YES];
[window setTitle:@"Window"];
// get the window's content view, where everything goes
NSView *contentView = [window contentView];
NSRect bounds = [contentView bounds];
// create a button
CGFloat width = 120.0, height = 32.0;
NSRect buttonRect = NSMakeRect(floor((NSWidth(bounds) - width)/2), floor((NSHeight(bounds)-height)/2), width, height);
NSButton *button = [[NSButton alloc] initWithFrame:buttonRect];
[button setAutoresizingMask:NSViewMinXMargin | NSViewMaxXMargin | NSViewMinYMargin | NSViewMaxYMargin];
[button setButtonType:NSMomentaryLightButton];
[button setBezelStyle:NSRoundedBezelStyle];
[button setFont:[NSFont systemFontOfSize:13.0]];
[button setTitle:NSLocalizedString(@"Hello World", nil)];
[button setTarget:self];
[button setAction:@selector(buttonAction:)];
// add the button to the window
[contentView addSubview:button];
[button release];
// center and open the window
[window center];
[window makeKeyAndOrderFront:nil];
}