GNUstep Gorm第一个视窗程序,第一个图形界面,第一个helloworld gui

news/2024/7/8 5:27:34 标签: 图形, menu, action, installer, attributes, makefile
GNUstep是苹果系统下开发语言Objective-C在windows或linux下进行开发的一种平台,为我们这些暂时没有苹果电脑,却想要学习的人提供了方便,但是毕竟是不同,没有太多教程,靠我们自己摸索了.
    网上倒是有许多关于GNUstep的第一个helloworld,但是是命令行的,图形界面,第一个视窗程序也有,
在一个页面的GNUstep教程 ,是英文的,也有对应的繁体版本,在 GNUstep 入門(官方的吧) ,但是非常难懂,我看了许久才明白是怎么回事,其实很简单,但是除了这个,网上就没有对应的gui helloworld的教程了,我就在这里发一个!
    前提:你必须安装 GNUstep的core和system,安装一个应用程序app,在
GNUstep Windows Installer页面下方 ,除了必须的,还有一些app,如下,选择Gorm,下载!
  • SystemPreferences 1.1.0
  • Gorm 1.2.10

    接下来我们开始!
一,不用Gorm的第一个图形界面,helloworld!
    这个helloworld程序共有五个文件:main.m、AppController.h、AppController.m、helloworldInfo.plist和GNUmakefile图形界面的设计全部在代码中,和第二个程序不一样,第二个程序的图形界面设计在.gorm的二进制文件中,如果是.nib文件,不是二进制,是xml格式的.既然在Gorm下开发,就用.gorm文件吧,

Main.m

#include "AppController.h"
#include <AppKit/AppKit.h>

int main(int argc, const char *argv[]) 
{
   NSAutoreleasePool *pool;
   AppController *delegate;
   
   pool = [[NSAutoreleasePool alloc] init];
   delegate = [[AppController alloc] init];

   [NSApplication sharedApplication];
   [NSApp setDelegate: delegate];

   RELEASE(pool);
   return NSApplicationMain (argc, argv);
}

AppController.h

#ifndef _AppController_H_
#define _AppController_H_

#include <Foundation/NSObject.h>

@class NSWindow;
@class NSTextField;
@class NSNotification;

@interface AppController : NSObject
{
   NSWindow *window;
   NSTextField *label;
}

- (void)applicationWillFinishLaunching:(NSNotification *) not;
- (void)applicationDidFinishLaunching:(NSNotification *) not;

@end

#endif /* _AppController_H_ */

AppController.m

#include "AppController.h"
#include <AppKit/AppKit.h>

@implementation AppController
- (void) applicationWillFinishLaunching: (NSNotification *) not
{
   /* Create Menu */
   NSMenu *menu;
   NSMenu *info;

   menu = [NSMenu new];
   [menu addItemWithTitle: @"Info"
                   action: NULL
            keyEquivalent: @""];
   [menu addItemWithTitle: @"Hide"
                   action: @selector(hide:)
            keyEquivalent: @"h"];
   [menu addItemWithTitle: @"Quit"
                   action: @selector(terminate:)
            keyEquivalent: @"q"];

   info = [NSMenu new];
   [info addItemWithTitle: @"Info Panel..."
                   action: @selector(orderFrontStandardInfoPanel:)
            keyEquivalent: @""];
   [info addItemWithTitle: @"Preferences"
                   action: NULL 
            keyEquivalent: @""];
   [info addItemWithTitle: @"Help"
                   action: @selector (orderFrontHelpPanel:)
            keyEquivalent: @"?"];

   [menu setSubmenu: info 
            forItem: [menu itemWithTitle:@"Info"]];
   RELEASE(info);

   [NSApp setMainMenu:menu];
   RELEASE(menu);

   /* Create Window */
   window = [[NSWindow alloc] initWithContentRect: NSMakeRect(300, 300, 200, 100)
                              styleMask: (NSTitledWindowMask |
                                          NSMiniaturizableWindowMask |
                                          NSResizableWindowMask)
                               backing: NSBackingStoreBuffered
                               defer: YES];
   [window setTitle: @"Hello World"];

   /* Create Label */
   label = [[NSTextField alloc] initWithFrame: NSMakeRect(30, 30, 80, 30)]; 
   [label setSelectable: NO];
   [label setBezeled: NO];
   [label setDrawsBackground: NO];
   [label setStringValue: @"Hello World"];

   [[window contentView] addSubview: label];
   RELEASE(label);
}

- (void) applicationDidFinishLaunching: (NSNotification *) not
{
   [window makeKeyAndOrderFront: self];
}

- (void) dealloc
{
  RELEASE(window);
  [super dealloc];
}

@end

接下来是helloworldInfo.plist文件:

{
   ApplicationDescription = "Hello World Tutorial";
   ApplicationIcon = "";
   ApplicationName = HelloWorld;
   ApplicationRelease = 0.1;
   Authors = "";
   Copyright = "Copyright (C) 200x by ...";
   CopyrightDescription = "Released under...";
   FullVersionID = 0.1;
   URL = "";
}

最后是比较重要的GNUmakefile:

GNUSTEP_MAKEFILES=/GNUstep/System/Library/Makefiles

include $(GNUSTEP_MAKEFILES)/common.make

APP_NAME = HelloWorld
HelloWorld_HEADERS = AppController.h
HelloWorld_OBJC_FILES = main.m AppController.m
HelloWorld_RESOURCE_FILES = HelloWorldInfo.plist

include $(GNUSTEP_MAKEFILES)/application.make

注意:在GNUmakefile当中,第一行为GNUstep的Makefile文件夹的变量,本来应该在路径中的,但是我运行的时候找不到这些make文件,所以我手工添加.
    接下来,把这些文件放到一个文件夹下,如helloworld1,然后运行sh,或者从GNUstep的shell,cd到这里,运行make就ok了!!如果已经运行过,会什么也不干,你需要 make clean;make就ok了!
接下来运行./HelloWorld.app/HelloWorld.exe,欣赏你的gui 的helloworld程序吧.
    附件:如果你懒得自己copy或者自己写,我传个附件:
Helloworld1

二,使用Gorm的第一个图形界面,helloworld!
    打开Gorm,你不会?如果你安装了Gorm,打开sh,然后运行/GNUstep/Local/Tools/Gorm,此时sh处于占用状态,Ctrl+C则会关闭Gorm.其实这个Gorm是个脚本,真正的程序在/GNUstep/Local/Applications/Gorm.app/Gorm.exe 。

#! /bin/sh

exec openapp "Gorm" "$@"


   下面我们开始,打开Gorm后,在主菜单,一般位于左上角,点击Document->New Application就会出现一个简单的窗口叫My Window,除了菜单,重要的设计窗口还有Untitled-7(你的程序名称,不知道怎么称呼这个窗口),Palette窗口,一般的控件都是从这里面拖出来的;Inspect窗口,设置各种属性.

    接下来我们开始设计.
    1.改变My Window的大小和设置标题,拖拉此窗口右下角(鼠标形状不变,让我崩溃),让窗口变小点;标题必须在Inspect手动设置,先点击下My Window,Inspect就会出现My Window的属性,在Title文本域输入你要的标题:Hello GNUstep Window,同时标题也变了,至于窗口大小也可以在Inspect窗口改变,点击Attributes,出现下拉菜单,选择size,改变即可,这个就不贴图了.


    2.添加一个Title控件,在palettes窗口中,拖动Title到你的窗口中.


再双击这个Title,直接输入你要的内容:HelloWorld
    3.再你的窗口菜单中添加info子菜单:



有个莫民奇妙的bug,运行后的菜单info->info panel有时候无法显示,选择两次,app崩溃.


http://www.niftyadmin.cn/n/1738491.html

相关文章

专题介绍是什么意思_解梦专题:做梦梦见自己拉屎是什么意思

做梦梦见自己拉屎什么意思是什么意思&#xff0c;好不好&#xff1f;预示什么&#xff1f;梦见自己拉屎什么意思有现实的影响和反应&#xff0c;也有梦者的主观想象&#xff0c;请看下面由精心为你整理的关于梦见自己拉屎什么意思的好坏含义&#xff0c;周公解梦大全。梦见自己…

Xcode 4 免证书开发调试 来源:Xcode 3.2.5免证书开发调试

Xcode 4 免证书开发调试 来源&#xff1a;Xcode 3.2.5免证书开发调试 我的开发环境是&#xff1a; 环境&#xff1a; Mac OS X&#xff1a;10.6.7 Xcode&#xff1a;4.0 iPhone SDKs&#xff1a;4.3 iTouch&#xff1a;4.2.1 Xcode编译遇到过 Code Sign error: a validprovi…

imp 只导表前10条数据_Oracle导入dmp文件时,跳过一些表不导,因为这些表的数据量过大,下面的语句不能导...

展开全部如果只是排除表几个表的话&#xff0c;636f707962616964757a686964616f31333365646235假设是排除A&#xff0c;B两个表&#xff0c;基本写法是impdp system/oracletestdb dumpfiletest.dmp logfileimp_test.log excludetable:\"in (A,B)\"就可以了&#xff0…

feign调用service_SpringCloud声明式服务调用Feign

前面使用了Ribbon做客户端负载均衡&#xff0c;使用Hystrix做容错保护&#xff0c;这两者被作为基础工具类框架被广泛地应用在各个微服务的实现中。SpringCloudFeign是将两者做了更高层次的封装以简化开发。它基于Netfix Feign实现&#xff0c;整合了SpringCloudRibbon和Spring…

python修复老照片_三行python代码还原老照片,开启超清会员模式!

原理如果之前了解过信号处理&#xff0c;就会知道最直接的方法是计算图片的快速傅里叶变换&#xff0c;然后查看高低频分布。如果图片有少量的高频成分&#xff0c;那么该图片就可以被认为是模糊的。然而&#xff0c;区分高频量多少的具体阈值却是十分困难的&#xff0c;不恰当…

比较QT和MFC两个界面库

确切说应该比较的是QT和MFC两个界面库 QT使用的编译器是MinGW&#xff0c;即Linux下的GCC移植到windows的版本 MFC使用的编译器是Visual C QT的应用主要在Linux下&#xff0c;但是它本身是跨平台的&#xff0c;也支持其他操作系统&#xff0c;是现在比较著名的界面库&#xff0…

ios 横向滚轮效果_ios uicollectionview实现横向滚动

现在使用卡片效果的app很多&#xff0c;之前公司让实现一种卡片效果&#xff0c;就写了一篇关于实现卡片的文章。文章最后附有demo实现上我选择了使用UICollectionView &#xff1b;用UICollectionViewFlowLayout来定制样式&#xff1b;下面看看具体实现效果实现上我选择了使用…

XPATH语法笔记

目录 1. 基本的XPath语法类似于在一个文件系统中定位文件,如果路径以斜线 / 开始, 那么该路径就表示到一个元素的绝对路径 1 2. 如果路径以双斜线 // 开头, 则表示选择文档中所有满足双斜线//之后规则的元素(无论层级关系)2 3. 星号 * 表示选择所有由星…